This variable is commonly encountered in frontend builds or Node.js development, but I never systematically understood its origins or impact. Here’s a summary.
- NODE_ENV is an environment variable.
- Installing Node.js or Webpack does not set this variable; we usually need to set it ourselves. Before setting it, printing it will show undefined.
- This environment variable was introduced by Express and has now become a conventional practice.
- Whether setting NODE_ENV to development/production or other values makes a difference depends on whether the tools used rely on this value. For example, in webpack, we sometimes selectively enable certain plugin processing based on NODE_ENV, such as hash fingerprint generation.
Modifying the Value in Projects
For CI builds, we often set this value at the Docker container level. For local development, where we need flexibility between projects, project-level control is better.
$ cross-env NODE_ENV=production node testaaa.js
Environment Variables
When I was doing Java development, I often had to configure Path and ClassPath, which are system environment variables.
Viewing Environment Variables on macOS
$ env
$ echo $NODE_ENV
Final Thoughts
Done.

