js_path

The `js_path` directive specifies the path to JavaScript files used for executing scripts in NGINX's stream module context.

Syntaxjs_path /path/to/script.js;
Defaultnone
Contextstream, stream server
Arguments1

Description

The js_path directive is used within the NGINX stream module to define the file pathname where JavaScript scripts reside. This functionality is vital for integrating JavaScript scripting via the NJS module into stream operations. The specified path can point to a single JavaScript file that contains the logic required for processing events in the stream context, allowing for the manipulation of data packets in real-time or the handling of protocols that require script-based customization.

The argument to the js_path directive must be a valid file path that NGINX can access. When the NGINX server processes requests, it will load the JavaScript file defined by this directive and execute its contents accordingly. The scripts written in NJS (NGINX JavaScript) can include event-driven programming elements, which provide a flexible way to handle tasks like modifying or redirecting streams based on specific conditions.

It is critical to ensure that the specified script is in a location that the NGINX worker processes have read access to, otherwise, errors will occur during operation. Additionally, the JavaScript file must be properly coded and syntactically correct to avoid runtime failures during NGINX execution. Overall, the js_path directive is a powerful tool that bridges the capabilities of JavaScript with NGINX's efficient stream processing features.

Config Example

stream {
    js_path /usr/local/nginx/scripts/my_script.js;
}

Ensure that the JavaScript file has the correct permissions for NGINX to read.

The file path must be absolute, or else NGINX may not find it during execution.

Syntax errors in the JavaScript file can lead to runtime failures and may not be easy to debug.

← Back to all directives