VOOZH about

URL: https://www.geeksforgeeks.org/node-js/how-to-add-pug-engine-in-express-js/

โ‡ฑ How to add pug engine in Express.js ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to add pug engine in Express.js ?

Last Updated : 28 Apr, 2025

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.

๐Ÿ‘ Image
 

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
๐Ÿ‘ Image
 

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

npm install pug --save
๐Ÿ‘ Image
 

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

express --pug 

or 

express --view=pug
๐Ÿ‘ Image
 

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.

Output:

๐Ÿ‘ Image
 

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

Comment

Explore