VOOZH about

URL: https://www.geeksforgeeks.org/node-js/how-to-do-templating-using-expressjs-in-node-js/

⇱ How to do Templating using ExpressJS in Node.js ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to do Templating using ExpressJS in Node.js ?

Last Updated : 11 Apr, 2023

Template Engine : A template engine basically helps us to use the static template files with minimal code. At runtime, the template engine replaces all the variables with actual values at the client-side.

Templating Engine Examples:
  • EJS (Embedded JavaScript Templating)
  • Pug
  • Mustache

In this article we are going to use EJS engine.

  • Setting up NPM packages:

    npm init -y
  • Installing Dependencies 
    npm install ejs express --save
Basic ExpressJS Server: Output:
👁 Image

Adding of EJS Engine: Here we need to set ejs as our view engine.

Filename: index.ejs Output:
👁 Image
output
Rendering of EJS file: Storing of data :  Here we have to store the data var name = "<%= data %>". Output:
👁 Image
Comment

Explore