

views folder to be our templates folder. We can use the res.render method to render our variables to our templates.įirst, we create the views folder to store our templates as we set the. The command above will install pug view engine for us to use. To install the template engine library, we can run something like the following: npm install pug -save It’ll set the templates folder to the views directory of our app.Īlso, we can set the view engine we want to use by setting the view engine property as follows: app.set('view engine', 'pug') To set the templates folder, we can set the views property by writing the following: app.set('views', './views') To render template files, we can set the application settings. The default for the Express application generator is Jade, but we can use the other ones listed as well. We can use popular template engines with Express, like Pug, Mustache, and EJS. In this article, we’ll look at how to set the template engine of our app, and returning HTML responses. Templates are convenient and we can use them in a much more flexible way than HTML strings. To render an HTML response with an Express route, we should return it as a template with the variable interpolated rather than return it directly as an HTML string.
