Another JS subset

nginScript, a new JavaScript-based language from nginx, gets panned

JAXenter Editorial Team
JavaScript image via Shutterstock

nginx, the company behind the popular open source web server, have unveiled a new JavaScript-based configuration language and a working prototype of a JavaScript VM. A lot of developers are asking the same question with the release: “What’s the point?”

The minds behind nginx, the open source web server used by Netflix, Pinterest, Hulu and GitHub, have unveiled nginScript: a JavaScript-based configuration language that’s deemed more effective for server configuration.

However, comments on the post introducing the new language haven’t all been kind, with a lot of developers lamenting the fact that another subset of JavaScript has been created. Others asked the very straight-forward question: What exactly is the purpose of this?

JavaScript was considered a good fit for the way nginx is configured according to CTO Igor Sysoev. While Lua is supported and perceived as a good tool, it wasn’t popular enough for nginx tastes. Scripting capabilities have been highlighted as the main motivation behind the new language.

How is nginScript structured?

nginScript, being an implementation of JavaScript, should hopefully be easy for those experienced in JavaScript code. It leaves out the less relevant built-in objects of JavaScript and consists of two parts: a specialised VM byte-code compiler and a configuration syntax for embedding JavaScript snippets.

Two new directives, js_set and js_run, are what you’ll need to insert JavaScript into the server. js_set sets the value of a variable to the result of the execution of JavaScript code:

http {
    js_set $hello_world "
            var str = 'Hello World!';
            // JavaScript

    server {
        location /{
            return 200 $hello_world;

js_run is used to execute JavaScript natively and generate an HTTP response:

location / {
    js_run "
        var res;
        res = $r.response;
        res.status = 200;
        res.send('Hello World!');

An example of gaining access to request parameters and routing traffic based on URI are also available on the announcement page.

Why was nginScript conceived?

Although developers explicitly point out that nginScript is still in the early stages of development, it’s so far been used in the defence against security threats and control of traffic. The consolidation of functions across different applications and faster application development with functional libraries is also made possible.

Having said that, a lot of the criticism nginx is receiving comes thanks to their recently launched working prototype of a JavaScript VM that would be embedded within the web server. This, coupled with their new config language, is earning the company comments such as “You should have saved this announcement for April 1st”.

And lets not forget the support for Lua:

nginScript is said to complement (not replace) Lua and other embedded languages. The team behind its development hope to roll out a number of nginx extensions in future.

More information about nginScript can be found at its Mercurial repository.

Inline Feedbacks
View all comments