![]() |
VOOZH | about |
In Pug, "includes" are a way to modularize and reuse code by importing separate Pug files into a main Pug file. This helps in organizing code more efficiently and reduces duplication of code by allowing you to include common sections or components across multiple pages easily. In simple words, Includes allows you to insert the contents of one Pug file into another.
The syntax for including a file in Pug is straightforward. You use the include keyword followed by the path to the file you want to include. Pug then processes these files during compilation and includes their content in the main file.
include filename_withpathStep 1: Create a Node.js application using the following command:
npm initStep 2: Install required Dependencies
npm i pug express👁 Screenshot-2024-03-19-121957
The updated dependencies in package.json file will look like:
"dependencies": {
"express": "^4.18.2",
"pug": "^3.0.2"
}
Example: This example demonstrate the use of Include keyword.
Step 4: To run the application use the following command
node index.js Output: Now go to http://localhost:3000 in your browser: