Open In App

How to add pug engine in Express.js ?

Last Updated : 28 Apr, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

Express is a small framework that sits on top of Node.js web server functionality to simplify its APIs and add helpful new features. It makes it easier to organize your application’s functionality with middleware and routing; it adds helpful utilities to Node.js’s HTTP objects; it facilitates the rendering of dynamic HTTP objects. 

In this article, we are going to learn how to use the pug engine in Express.js.

Let us first start by creating a node.js project named pug. For that let's create the folder named pug and run the command npm init in it.

 

Now that we have set up our project, let's now install the necessary packages.

First, we install Express.js, to install we will run the command:

npm install express --save
 

Next, we will install pug. Run the following command to install:

npm install pug --save
 

Now to set pug as the view engine, run the command:

express --pug 

or 

express --view=pug
 

Now run the project by using the command:

npm start

Example: You can edit the content of the file index.pug to change the content of the screen.

HTML
extends layout

block content
  h1= title
  p Welcome to #{title}
  p Let's start using Pug

Output:

 

Now you are ready to start using the pug template engine in express in your projects.


Next Article

Similar Reads