Pug was formerly called Jade until it’s version 2.0 was released in 2015.
Let’s make a basic pug template using express.js:
Prerequisite: Basic working knowledge of express is required.
Step 1: Make an empty project folder. In command prompt / terminal, run npm init to intialize package.json file:
npm init -y
-y flag is for default settings in package.json.
Step 2: Install express and pug. We will directly install ‘express’ package rather than generating our express app with ‘express-generator’ for simplicity reasons. You can optionally install nodemon for hot reloading.
npm install express pug
Our final directory structure will look like this:
Step 4: Setting up a basic express app. In Index.js:
Step 5: In index.pug file:
You can read basics of pug syntax here.
Step 6: In terminal start the application. Run nodemon command if we have installed it previously, or just simply use node.
node index.js or nodemon index.js
In browser on localhost 3000 port, we get the below rendered template: