Node.js upgrade adds environment variable config

The JavaScript runtime also boasts ECMAScript modules.

Node.js upgrade adds environment variable config
Gerd Altmann (CC0)

Node.js 20.6.0, the latest version of the asynchronous, event-driven JavaScript runtime, includes built-in env. file support for configuring environment variables.

The update, cited as the “current” version of Node.js and announced September 4, can be downloaded from the project website. With env., Node.js proponents said the configuration file should follow the INI file format, with each line having a key-value pair for an environment variable. To initialize the Node.js application with predefined configurations, developers can use this CLI command: node—file=config.env index.js. In addition, the change for environment variables enables definition of NODE_OPTIONS directly in the .env file, eliminating the need to put it in package.json.

Also in Version 20.6.0, in ECMAScript modules, import.meta.resolve(specifier) can be used to obtain an absolute URL string to which specifier. And a new register API, available on node.module, enables specification of a file that exports module customization hooks. Data can be passed to these hooks.

Elsewhere in Node.js 20.60.0:

  • When Node.js starts up, it now ensures there is a v8::CppHeap attached to the V8 isolate. This lets users allocate in the v8::CppHeap using <cppgc/*> headers from the V8 JavaScript engine, which are now included in the Node.js headers available to add-ons.
  • To help with development of JavaScript-to-C++ references, of which the V8 garbage collector can be aware, a helper function, node::SetCppgcReference(isolate, js_object, cppgc_object) has been added to node.h. This API can be used to avoid hard-coding the layout of JavaScript wrapper objects. V8 may provide a native alternative in the future, which could replace this Node.js-specific helper.

Copyright © 2023 IDG Communications, Inc.