EJS
By the EJS open-source community
js that lets developers write HTML with embedded JavaScript code directly inside special tag delimiters, allowing loops, conditionals, and expressions to appear in-line without learning a separate template-specific syntax. js projects.
Definition
EJS, short for Embedded JavaScript, is a templating engine for Node.js that lets developers write HTML with embedded JavaScript code directly inside special tag delimiters, allowing loops, conditionals, and expressions to appear in-line without learning a separate template-specific syntax. It compiles templates into cached JavaScript functions and is frequently used as a default view engine in Express applications and other server-rendered Node.js projects.
Overview
EJS was designed around a simple premise: rather than inventing a new syntax for template logic, let developers write actual JavaScript inside the markup they already know. A template looks like ordinary HTML with small tags such as `<%= %>` for escaped output, `<%- %>` for unescaped output, and `<% %>` for control-flow statements like loops and conditionals, all of which contain real JavaScript expressions or statements rather than a template-specific mini-language. When a template is rendered, EJS parses the source text into a JavaScript function body, treating everything outside the tags as string literals to be concatenated and everything inside the tags as executable code, then compiles that function once and caches it for reuse across multiple render calls with different data. This close mapping to plain JavaScript means anything expressible in a one-line JavaScript statement can appear in a template, including calling helper functions passed in through the render context, without EJS needing to implement equivalents of every control structure itself. This approach places EJS at the more permissive end of the templating spectrum, in contrast to logic-less engines like Mustache that deliberately restrict what a template can express, and it differs from Pug's indentation-based syntax by keeping conventional HTML tags and angle brackets intact, which many developers find easier to read alongside existing markup or to convert from static HTML mockups. It is closer in philosophy to PHP's inline code blocks or ASP's classic templating than to declarative engines like Jinja that use their own filter and expression syntax. EJS is commonly used to render server-side views in Express applications, to generate email bodies with dynamic content, and to produce static HTML output during build steps for simple sites. Because template files remain close to plain HTML, teams often use EJS specifically to ease the transition from static HTML prototypes into dynamic server-rendered pages without a large syntactic jump. The same flexibility that makes EJS approachable also makes it easy to embed too much business logic directly inside templates, which can blur the separation between presentation and application code that more restrictive engines enforce by design; teams have to apply their own discipline to keep templates focused on rendering rather than computation. EJS also lacks some of the built-in structural conveniences of engines like Nunjucks or Jinja, such as macros or extensive filter libraries, so more complex reuse patterns often require passing in JavaScript helper functions manually.
Key Features
- Embeds real JavaScript expressions and statements inside HTML tags
- Separate tag syntax for escaped output, raw output, and control flow
- Compiles templates into cached JavaScript rendering functions
- Familiar HTML-like syntax that eases conversion from static markup
- Supports partials for including other templates within a page
- Works as a drop-in Express view engine with minimal configuration
- No proprietary expression language to learn beyond plain JavaScript