About nginScript

nginScript is a subset of the JavaScript language that allows implementing location and variable handlers in http and stream. nginScript is created in compliance with ECMAScript 5.1 with some ECMAScript 6 extensions. The compliance is still evolving.

What is currently supported

  • Boolean values, numbers, strings, objects, arrays, functions, and regular expressions
  • ES5.1 operators, ES7 exponentiation operators
  • ES5.1 statements: var, if, else, switch, for, for in, while, do while, break, continue, return, try, catch, throw, finally
  • ES6 Number and Math properties and methods
  • String methods:
    • ES5.1: fromCharCode, concat, slice, substring, substr, charAt, charCodeAt, indexOf, lastIndexOf, toLowerCase, toUpperCase, trim, search, match, split, replace
    • ES6: fromCodePoint, codePointAt, includes, startsWith, endsWith, repeat
    • non-standard: fromUTF8, toUTF8, fromBytes, toBytes
  • Object: rudimentary Object.create() support without properties list
  • Array methods:
    • ES5.1: isArray, slice, splice, push, pop, unshift, shift, reverse, sort, join, concat, indexOf, lastIndexOf, forEach, some, every, filter, map, reduce, reduceRight
    • ES6: of, fill, find, findIndex
    • ES7: includes
  • ES5.1 Function methods: call, apply, bind
  • ES5.1 RegExp methods: test, exec
  • ES5.1 Date methods
  • ES5.1 global functions: isFinite, isNaN, parseFloat, parseInt, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent

What is not supported yet

  • ES6 let and const declarations
  • labels
  • arguments array
  • eval function
  • JSON object
  • Error object
  • setTimeout, setInterval, setImmediate functions
  • non-integer fractions (.235), exponential (3.35e10), binary (0b0101), octal (0o77), hexadecimal (0x1123) literals

Download and install

nginScript is available in two modules:

Both modules are not built by default, they should be either compiled from the sources or installed as a Linux package.

Installing as a Linux package

For Linux, nginScript modules packages can be used:

  • nginx-module-njs — nginScript dynamic modules
  • nginx-module-njs-dbg — debug symbols for the nginx-module-njs package

Building from the sources

The repository with nginScript sources can be cloned with the following command: (requires Mercurial client):

hg clone http://hg.nginx.org/njs

Then the modules should be compiled using the --add_module configuration parameter:

./configure --add-module=path-to-njs/nginx

The modules can also be built as dynamic:

./configure --add-dynamic_module=path-to-njs/nginx

© 2002-2017 Igor Sysoev
© 2011-2017 Nginx, Inc.
Licensed under the BSD License.