explaingit

mozilla/nunjucks

8,947JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A JavaScript templating engine from Mozilla that lets you build HTML pages with reusable layouts and variable data, inspired by Python's Jinja2. Works in Node.js and the browser.

Mindmap

mindmap
  root((nunjucks))
    What it does
      HTML templating
      Template inheritance
      Async support
    Environments
      Node.js server
      Browser client
    Key features
      Jinja2 inspired
      Layout reuse
      Variable fill-in
    Audience
      Web developers
      Node.js users
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a Node.js website where all pages share a common header and footer by using Nunjucks template inheritance.

USE CASE 2

Generate HTML emails or reports from JSON data by writing a template with placeholder syntax that Nunjucks fills in at runtime.

USE CASE 3

Add server-side rendering to an Express.js app so dynamic pages load without a front-end JavaScript framework.

Tech stack

JavaScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Nunjucks is a templating engine for JavaScript, maintained by Mozilla. A templating engine is a tool that lets you build HTML pages (or other text files) by combining a fixed structure with variable data. Instead of writing the same HTML repeatedly with slightly different content, you write the structure once using special placeholder syntax, and the engine fills in the values at runtime. Nunjucks is inspired by Jinja2, a popular Python templating system, and brings a similar feature set to JavaScript. It supports template inheritance, which means you can define a base page layout and have other templates extend it, avoiding repeated code. It also handles asynchronous operations, which matters in JavaScript where many tasks happen in a non-blocking way. It works both on the server side (in Node.js) and in the browser. Installation is a single command via npm, the standard JavaScript package manager. The documentation is hosted separately on GitHub Pages. The README for this project is brief and points to the external documentation site for full details. This is a developer utility, not an end-user application.

Copy-paste prompts

Prompt 1
I'm building a Node.js Express app and want to use Nunjucks for HTML pages. Show me how to set Nunjucks as the view engine and create a base template that other pages extend.
Prompt 2
I have a JSON array of products and want to generate an HTML table from it using Nunjucks. Show me the template syntax for looping through the array and displaying each field.
Prompt 3
How do I use Nunjucks in the browser to render templates on the client side without a Node.js server?
Open on GitHub → Explain another repo

← mozilla on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.