Generate HTML with plain JS.

No new syntax, no special directives. Write the JavaScript you already know, right inside your HTML.

20M+
Weekly downloads
7.7k
GitHub stars
0
Dependencies
$ npm install ejs
Get Started

What is EJS?

What is the "E" for? "Embedded?" Could be. How about "Effective," "Elegant," or just "Easy"? EJS is a simple templating language that lets you generate HTML markup with plain JavaScript. No religiousness about how to organize things. No reinvention of iteration and control-flow.

Use plain JavaScript

All templating languages grow to be Turing-complete. Just cut out the middle-man and use the JavaScript you already know.

  • Server & browser
  • Express view engine

Fast development

Don't waste time figuring out arcane new syntax or how to preprocess your data so it renders right.

  • Sub-template includes
  • Bundled CLI

Simple syntax

JavaScript code in simple scriptlet tags. Just write JS that emits the HTML you want.

  • <% %> tags
  • Custom delimiters

Speedy execution

Templating that never shows up in your performance budget. Fast enough you can forget it's there.

  • Fast compile & render
  • Caches compiled JS
  • Caches templates

Easy debugging

When something breaks, you're not stuck deciphering a black box. Debug it like any other JavaScript.

  • Plain JS exceptions
  • Template line numbers

Active development

Large community, active maintainers. We're happy to answer questions or give help.

  • Apache-2.0 licensed
  • Zero dependencies

A note for security professionals

Before reporting any security issues, please reference the SECURITY.md for this project.

If you give end-users unfettered access to the EJS render method, you are using EJS in an inherently un-secure way.

EJS is effectively a JavaScript runtime. If you run the render method without checking inputs yourself, you are responsible for the results.

In short, do not submit vulnerabilities that include this snippet:
app.get('/', (req, res) => {
  res.render('index', req.query);
});

Zero new concepts.

Other templating languages invent their own dialect for loops, conditionals, and partials. EJS just uses JavaScript. No new keywords or helper APIs to learn.

Handlebars
{{#if user.loggedIn}}
  Hello, {{user.name}}!
{{else}}
  Hello, Guest!
{{/if}}
Pug
if user.loggedIn
  | Hello, #{user.name}!
else
  | Hello, Guest!
Mustache
{{#user.loggedIn}}
  Hello, {{user.name}}!
{{/user.loggedIn}}
{{^user.loggedIn}}
  Hello, Guest!
{{/user.loggedIn}}
<% EJS %>
<% if (user.loggedIn) { %>
  Hello, <%= user.name %>!
<% } else { %>
  Hello, Guest!
<% } %>
  • No helpers to register
  • Full JavaScript expressions
  • Runs in Node & the browser
  • Zero dependencies
  • Compiled & cached for speed
  • Express view engine

Up and running in minutes.

Install EJS, pick your module system, and start generating HTML with plain JavaScript.

Install via npm

Add EJS to your project with a single command.
$ npm install ejs

ESM or CJS

Pick the module system that fits your project.
import ejs from 'ejs';

Render a template

Pass EJS a template string and some data. You've got HTML.
render.js
import ejs from 'ejs';
let people = ['geddy', 'neil', 'alex'];
let html = ejs.render('<%= people.join(", "); %>', {people});

Use the command line

Feed it a template file and a data file, specify an output file.
$ ejs ./template.ejs -f data.json -o ./output.html

Browser support

Download a browser build and drop it in a script tag.
index.html
<script src="ejs.js"></script>
<script>
  let html = ejs.render('<%= people.join(", "); %>', {people});
</script>

Need help?

Stack Overflow

Ask questions about specific problems you've faced. Tag your question with ejs and browse existing answers.

GitHub Issues

The preferred channel for bug reports, feature requests, and pull requests. Check existing issues before opening a new one.

Ready to build?

Read the Docs