Home ยป Enhanced functionality of NodeJS: Intrinsic .env file compatibility eliminates the need for additional modules.

Enhanced functionality of NodeJS: Intrinsic .env file compatibility eliminates the need for additional modules.

NodeJS has released version 20.6, and one significant change is the addition of the --env-file option, which directly supports loading environment variable values from NodeJS. This eliminates the need to install any additional modules. Normally, the variables under process.env retrieve values from pre-set environment variables in the running shell. If you want to read values from a file instead, you would typically need to use additional modules. However, besides setting configurations for your application, such as database passwords or URLs for external services, users can now also configure NodeJS itself through the NODE_OPTIONS variable.

Previously, developers who needed to use env files often relied on the popular dotenv module, which has been downloaded up to 34 million times per week. Other features of this release include support for loading modules before the application starts to create pre-hooks, improvements to the C++ extension system, and an update to v8.


node --env-file=config.env index.js

An .env file is a repository of key-value pairs formatted in the INI file structure. These files serve as a means to define both environment variables and Node options. The configuration of Node options is accomplished through the utilization of the NODE_OPTIONS environment variable, wherein a series of space-separated values are employed to specify command-line options in an alternative manner.

A widely-used Node module known as dotenv serves a comparable purpose. Nonetheless, it is important to note that this module is exclusively applicable within user code once Node has commenced execution, rendering it unsuitable for configuring the Node runtime itself.

Node.js has now incorporated support for Oilpan, alternatively recognized as cppgc, catering to developers crafting C++ add-ons for Node applications. Although the Application Binary Interface (ABI) stability of cppgc is not guaranteed, the Node team has expressed confidence in its reliability, stating, “we do not anticipate frequent ABI disruptions, as it has maintained stability and undergone rigorous testing within the Chromium ecosystem for an extended period.”

More Reading

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *