loose-envify(1)

loose-envify1

Replace node.js environment variables with plain strings

Usage

loose-envify <javascript_source_file.js>

Overview

Performs a Javascript source-to-source transformation (transpiling), that efficiently replaces Node.js process.env environment variables with plain strings. This makes the environment variable checks faster and easier to optimize out.

Examples

Running this source code:

if (process.env.NODE_ENV === "development") {
  console.log('development only')
}

through loose-envify:

loose-envify index.js > bundle.js

with NODE_ENV set to production results in:

if ("production" === "development") {
  console.log('development only')
}

which, when run through a minifier, would be stripped out completely.

However, if you run the same script through loose-envify with NODE_ENV set to development it gives:

if ("development" === "development") {
  console.log('development only')
}

The if statement will evaluate to true, so the code won't be removed.

Releases

5 releases since Debian 9 (Stretch); the text changed 3 times.

  1. 9
  2. 10
  3. 11
  4. 12–13

Author

Andres Suarez <[email protected]>

From node-loose-envify 1.4.0+dfsg1-4 in Debian 13 (Trixie). Parsed by carta from the page's man source.