BT

Nginx Announces nginScript, a JavaScript-based Configuration Language

| by David Iffland Follow 4 Followers on Sep 24, 2015. Estimated reading time: 1 minute |

Nginx has announced nginScript, a custom JavaScript implementation used to enable dynamic configuration and delivery within the web server. At this year's nginx.conf, nginx creator Igor Sysoev took to the stage to demonstrate the new feature.

Nginx already supports Lua for script-based configuration, but nginScript lowers the barrier of entry to those who already have a background in JavaScript. Rather than relying on an existing virtual machine, execution of the language is handled by a custom VM, purpose built for the requirements of nginx.

In use, nginScript allows the result of a JavaScript snippet to be used for configuration. In a blog post accompanying the announcement, Sysoev showcased a few possibilities. For example:

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

    server {
        ...
        location /{
            return 200 $hello_world;
        }
    }
}

In this example, the result of the snippet is stored in a variable $hello_world, which is then used as the response to a web request at a specific route. While it's possible to use nginScript to serve up an entire JavaScript-based web application, that's not the intent. The new language is a subset of JavaScript, so existing modules made for environments like node.js likely will not work. The nginScript documentation spells this out specifically:

We don’t plan to create an alternative to node.js, or any other application platforms. nginScript is targeted very firmly at extending the NGINX configuration to give you more control over HTTP traffic.

Over on Hacker News, reaction was mixed. User eknkc was encouraged:

I think it's a good addition. We have been using varnish on high traffic servers and one of the reasons was that it had "vcl", a JavaScript-like language to define request handling logic. Having JavaScript on nginx would provide a lot of config options for people familiar with it.

But others are cautiously optimistic. User CrLf said:

The usefulness of this is not to turn nginx into an application server. The point is to make nginx's configuration dynamic and prevent bloating applications with stuff that belongs at the (lets call it) devops level.

Nginx says they don't intend for nginScript to replace Lua, but given the pervasiveness of JavaScript in the community, it wouldn't be a surprise to see JavaScript overtake Lua in usage. For now, nginScript is available for testing and feedback in the mecurial repository.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT