

Open the folder newProject in Visual Studio Code (VSCode).

Use the IDE of your choice, in my case I am using Visual Studio Code. Start by creating a folder in a directory of your choice using the terminal.

In addition to the prerequisite mentioned above, you must be familiar with JavaScript. Click here to get Nodejs if you do not have one. To get hands on experience with this article you need to have: At the end of this tutorial, you would have created an single web page and learn how to use the technologies mentioned above. We will create a Node application from scratch, set up Nodejs, express, and a pug template engine. In this tutorial, I will explain how to use a pug template and NodeJS to build a web page. “Developing template engines for Express”.ĭocumentation translations provided by StrongLoop/IBM:įrench, German, Spanish, Italian, Japanese, Russian, Chinese, Traditional Chinese, Korean, Portuguese.Ĭommunity translation available for: Slovak, Ukrainian, Uzbek, Turkish and Thai.Image by Free-Photos from Pixabay Introduction To learn more about how template engines work in Express, see: The view is still re-rendered with every request even when the cache is on. Note: The view engine cache does not cache the contents of the template’s output, only the underlying template itself. When you make a request to the home page, the index.pug file will be rendered as HTML. You must specify the extension of the view file. Then create a route to render the index.pug file.

app.set('view engine', 'pug')Ĭreate a Pug template file named index.pug in the views directory, with the following content: html Library follows this convention by mapping all of the popular Node.js template engines, and therefore works seamlessly within Express.Īfter the view engine is set, you don’t have to specify the engine or load the template engine module in your app Įxpress loads the module internally, as shown below (for the above example). Some template engines do not follow this convention. Which is called by the res.render() function to render the template code. Express-compliant template engines such as Jade and Pug export a function named _express(filePath, options, callback),
