npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@inteli.city/node-red-contrib-template-njk

v1.0.0

Published

A Node-RED node that renders [Nunjucks](https://mozilla.github.io/nunjucks/) templates (Jinja2-inspired, by Mozilla).

Downloads

28

Readme

node-red-contrib-template-njk

A Node-RED node that renders Nunjucks templates (Jinja2-inspired, by Mozilla).

This node provides a subset of Nunjucks functionality. It renders templates from a string and does not support file-based features such as include, extends, or import.

Table of Contents

Install

cd ~/.node-red
npm install @inteli.city/node-red-contrib-template-njk

Node: template.njk

Renders a Nunjucks template using values from the incoming message, flow context, global context, and environment variables, then writes the result to a message property.


Template variables

Message properties are exposed at the root of the template context. Reference them directly without any msg. prefix.

| Variable | Value | |---|---| | {{ payload }} | msg.payload | | {{ topic }} | msg.topic | | {{ flow.get("key") }} | Flow context variable | | {{ global.get("key") }} | Global context variable | | {{ env.MY_VAR }} | OS environment variable |

{{ msg.payload }} is not supported. Using msg. in a template triggers a node error. Use {{ payload }} style instead.


Limitations

This node renders templates from a single string, not from files. This is a deliberate design choice that keeps templates self-contained and behavior predictable. Some Nunjucks features depend on a file system loader and are therefore not available.

Not supported

  • {% include "file.njk" %}
  • {% extends "base.njk" %}
  • {% import "macros.njk" %}

These features require a template loader (file system or external source), which this node intentionally does not provide.

No template modules

Templates are self-contained per node. There is no shared template system between nodes.

  • You cannot reuse templates across nodes
  • You cannot define global macros or libraries

You can still define and use macros within a single template:

{% macro greet(name) %}
Hello {{ name }}
{% endmacro %}

{{ greet("world") }}

No file system access

Templates are not loaded from disk. Everything must be defined inline in the node editor, or passed dynamically via msg.template.

No async features

Rendering is synchronous. Async filters and async loaders are not supported.

Controlled context

Only the following are available inside templates:

  • Message properties at the root (e.g. {{ payload }})
  • Flow context via flow.get("key")
  • Global context via global.get("key")
  • Environment variables via env.MY_VAR

Direct msg.* access is intentionally blocked.


Automatic JSON stringification

If msg.payload is an object or array, it is automatically converted to a JSON string before the template renders. This means you never need to manually stringify objects to use them in a template.

msg.payload = { city: "São Paulo", pop: 12300000 }

template:
  City: {{ payload }}

output:
  City: {"city":"São Paulo","pop":12300000}

The original msg.payload is never mutated — the stringification only applies inside the template context.


Output format

The rendered string can optionally be parsed before being written to the output property:

| Setting | Behaviour | |---|---| | Plain text | Result is written as a string (default) | | Parsed JSON | Result is passed through JSON.parse() | | Parsed YAML | Result is parsed with js-yaml | | Parsed XML | Result is parsed with xml-js (compact mode) |

The output property defaults to msg.payload. The property field in the editor lets you write to any msg, flow, or global property instead.


Nunjucks quick reference

{# output a variable #}
{{ payload }}

{# apply a filter #}
{{ payload | upper }}
{{ payload | replace("foo", "bar") }}

{# conditional #}
{% if payload %}
  has value
{% else %}
  empty
{% endif %}

{# loop #}
{% for item in items %}
  - {{ item }}
{% endfor %}

{# set a variable #}
{% set label = "hello" %}

{# define a macro (reusable within this template) #}
{% macro greet(name) %}Hello {{ name }}{% endmacro %}
{{ greet("world") }}

{# access flow / global context #}
{{ flow.get("myKey") }}
{{ global.get("config") }}

{# access environment variables #}
{{ env.HOME }}
{{ env.MY_CUSTOM_VAR }}

Full Nunjucks documentation (note: not all features are supported): https://mozilla.github.io/nunjucks/templating.html