njs-0.7.7
Dmitry Volyntsev
xeioex at nginx.com
Tue Aug 30 23:00:50 UTC 2022
Hello,
I'm glad to announce a new release of NGINX JavaScript module (njs).
Notable new features:
- advances fs API:
New API allows to open a file and read from and write to at
specified location without reading the whole file.
import fs from 'fs';
async function modifying_large_file() {
let fh = await fs.promises.open('/my/path');
let buf = Buffer.alloc(4);
await fh.read(buf, 0, 4, 64);
console.log(`read ${buf.toString('hex')}`);
// modify part
buf[0] = buf[0] ^ buf[3];
await fh.write(buf, 0, 4, 64);
console.log(`written ${buf.toString('hex')}`);
await fh.close();
}
Learn more about njs:
- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
https://nginx.org/en/docs/njs/typescript.html
Feel free to try it and give us feedback on:
- Github: https://github.com/nginx/njs/issues
- Mailing list: https://mailman.nginx.org/mailman/listinfo/nginx-devel
Additional examples and howtos can be found here:
- Github: https://github.com/nginx/njs-examples
Changes with njs 0.7.7 30 Aug 2022
nginx modules:
*) Feature: the number of nginx configuration contexts where
js directives can be specified is extended.
HTTP: js_import, js_path, js_set and js_var are allowed
in server and location contexts. js_content, js_body_filter
and js_header_filter are allowed in 'if' context.
Stream: js_import, js_path, js_set and js_var are allowed
in server context.
*) Feature: added r.internal property.
*) Bugfix: fixed reading response body in fetch API.
*) Bugfix: fixed "js_fetch_timeout" in stream module.
*) Bugfix: fixed socket leak with 0 fetch timeout.
Core:
*) Feature: extended "fs" module. Added fs.openSync(),
fs.promises.open(), fs.fstatSync(), fs.readSync(),
fs.writeSync().
The following properties of FileHandle are implemented:
fd, read(), stat(), write(), close().
*) Bugfix: fixed parseInt(), parseFloat(), Symbol.for()
with no arguments.
More information about the nginx
mailing list