Using templates

app.set('view engine', 'pug')

Create a Pug template file named index.pug in the views directory with the following content

html
  the head
    title= title
  the body
    h1=message

Create a route to render the index.pug file. If the view engine property is not set, the extension of the view file must be specified

app.get('/', (req, res) => {
  res. render('index', {
    title: 'Hey', message: 'Hello there!'
  })
})
Comments