view xml/en/docs/njs/index.xml @ 2555:5b2764724e0d

Added list of supported OSes to njs.
author Yaroslav Zhuravlev <yar@nginx.com>
date Fri, 19 Jun 2020 12:28:43 +0100
parents 0e6bbd8138c4
children c81b1fadbcf3
line wrap: on
line source

<?xml version="1.0"?>

<!--
  Copyright (C) Nginx, Inc.
  -->

<!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">

<article name="njs scripting language"
        link="/en/docs/njs/index.html"
        lang="en"
        rev="30"
        toc="no">

<section id="summary">

<para>
njs is a subset of the JavaScript language that allows
extending nginx functionality.
njs is created in compliance with
<link url="http://www.ecma-international.org/ecma-262/5.1/">ECMAScript 5.1</link>
(strict mode) with some
<link url="http://www.ecma-international.org/ecma-262/6.0/">ECMAScript 6</link>
and later extensions.
The compliance is still <link doc="compatibility.xml">evolving</link>.
</para>

</section>


<section id="links">

<para>
<list type="bullet">

<listitem>
<link doc="install.xml"/>
</listitem>

<listitem>
<link doc="changes.xml"/>
</listitem>

<listitem>
<link doc="reference.xml"/>
</listitem>

<listitem>
<link doc="examples.xml"/>
</listitem>

<listitem>
<link doc="compatibility.xml"/>
</listitem>

<listitem>
<link doc="cli.xml"/>
</listitem>

<listitem>
<link id="tested_os_and_platforms">Tested OS and platforms</link>
</listitem>

</list>
</para>

<para>
<list type="bullet">

<listitem>
<link doc="../http/ngx_http_js_module.xml">
ngx_http_js_module</link>
</listitem>

<listitem>
<link doc="../stream/ngx_stream_js_module.xml">
ngx_stream_js_module</link>
</listitem>

</list>
</para>

<para>
<list type="bullet">

<listitem>
<link doc="typescript.xml"/>
</listitem>

<listitem>
<link doc="node_modules.xml"/>
</listitem>

</list>
</para>

</section>


<section id="usecases" name="Use cases">

<para>
<list type="bullet">

<listitem>
Complex access control and security checks in njs
before a request reaches an upstream server
</listitem>

<listitem>
Manipulating response headers
</listitem>

<listitem>
Writing flexible asynchronous content handlers and filters
</listitem>

</list>
See <link doc="examples.xml">examples</link> and
<link url="https://www.nginx.com/blog/tag/nginx-javascript-module/">blog posts</link>
for more njs use cases.
</para>

</section>


<section id="example" name="Basic HTTP Example">

<para>
To use njs in nginx:
<list type="bullet">

<listitem>
<para>
<link doc="install.xml">install</link> njs scripting language
</para>
</listitem>

<listitem id="hello_world">
<para>
create an njs script file, for example, <path>hello_world.js</path>.
See <link doc="reference.xml">Reference</link>
for the list of njs properties and methods.
<example>
function hello(r) {
    r.return(200, "Hello world!");
}
</example>
</para>
</listitem>

<listitem>

<para>
in the <path>nginx.conf</path> file, enable
<link doc="../http/ngx_http_js_module.xml">ngx_http_js_module</link> module
and specify the
<link doc="../http/ngx_http_js_module.xml" id="js_include">js_include</link>
directive
with the <path>hello_world.js</path> script file:
<example>
load_module modules/ngx_http_js_module.so;

events {}

http {
    js_include hello_world.js;

    server {
        listen 8000;

        location / {
            js_content hello;
        }
    }
}

</example>
</para>
</listitem>

</list>
There is also a standalone <link doc="cli.xml">command line</link> utility
that can be used independently of nginx for njs development and debugging.
</para>

</section>


<section id="tested_os_and_platforms"
        name="Tested OS and platforms">

<para>
<list type="bullet">

<listitem>
FreeBSD / amd64;
</listitem>

<listitem>
Linux / x86, amd64, arm64, ppc64el;
</listitem>

<listitem>
Solaris 11 / amd64;
</listitem>

<listitem>
macOS / x86_64;
</listitem>

</list>
</para>

</section>


<section id="presentation" name="Presentation at nginx.conf 2018">

<para><video id="Jc_L6UffFOs" /></para>

</section>

</article>