In the previous section we installed Express and we set up our basic app.js
file and our package.json
file. So we have one route above going to the Home
page and all we're doing is just sending out some text inside an h1
tag.
We now want to load some Pug views for different routes in our application. But before we do that, we need to actually set up a couple of things.
Let's go to app.js
and let's type in app.set
. We need to tell Pug which folder the template files will be in, so we use views
. Then as the second parameter, we'll use path.join
and in there, we will put __dirname
as the first parameter and the second parameter will be the folder name, views
:
app.set('views', path.join(__dirname, 'views'));
We also need to set the view engine
, so I'll use app.set('view engine')
and then the second parameter will be pug
. Alright, now instead of typing in res.send
, we'll type in res.render
and we'll render the index
view:
app.set('view engine', 'pug'); app.use...