nginx JavaScript module

njs is an nginx module that extends the server's functionality through JavaScript scripting, enabling the creation of custom server-side logic and more.

nginx calls JavaScript handlers at a fixed set of integration points: HTTP request and response processing phases, stream session phases, variable evaluation, and periodic timers. njs is not a standalone application runtime: it has no start-up script and no event loop of its own, JavaScript code runs only when nginx invokes a configured handler, and control returns to nginx once the handler completes.

The built-in njs JavaScript engine is deprecated since 1.0.0; new configurations should use the QuickJS engine.

Getting started

Reference

Project

Use cases

See examples for more njs use cases.

Basic HTTP Example

To use njs in nginx:

There is also a standalone command line utility that can be used independently of nginx for njs development and debugging.

Tested OS and platforms

Presentation at nginx.conf 2018