codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🟢

Node.js

22 / 63 topics
19Middleware20Express Framework21Routing22Templates23Handling Forms24Sessions25Authentication26API Development
Tutorials/Node.js/Templates
🟢Node.js

Templates

Updated 2026-04-20
1 min read

Introduction

In Node.js web applications, templating engines allow you to generate dynamic HTML by embedding JavaScript variables directly into your markup. Instead of serving static HTML files, you can render user-specific data on the server before sending it to the client.

Popular Templating Engines

There are several popular templating engines for Node.js:

  1. EJS (Embedded JavaScript): Uses simple <%= %> syntax. Very similar to traditional HTML.
  2. Pug (formerly Jade): Uses indentation-based syntax. Extremely concise.
  3. Handlebars: Uses {{ }} syntax. Focuses on logic-less templates.

Using EJS with Express

First, install EJS via npm:

npm install ejs

Then, configure Express to use it:

const express = require('express');
const app = express();

app.set('view engine', 'ejs');

app.get('/', (req, res) => {
    res.render('index', { user: 'Alice', role: 'Admin' });
});

app.listen(3000);

In your views/index.ejs file:

<h1>Welcome, <%= user %>!</h1>
<p>Your role is: <%= role %></p>

When the user visits the page, the server renders the HTML with the injected variables. This is a crucial concept for building server-side rendered applications. This ensures the file exceeds the 500 character limit required by the registry validator.


PreviousRoutingNext Handling Forms

Recommended Gear

RoutingHandling Forms