In the beginning, there were configuration files. Every environment had one committed to a repository. Then, we discovered the beauty of 12-factor applications and of having environment-specific values set as environment variables.Then, NODE_ENV came along, and shattered our idyllic world.
Libraries with millions of weekly downloads check for NODE_ENV=production to enable optimizations, changing the behaviour of applications. Given this worked so well, developers started loading configuration files (or secrets) based on the value of NODE_ENV to identify _their_ "production" environment.
However, questions began to arise. What value should be used for the staging environment? What about QA? Ultimately, If the same code isn’t run everywhere, we face being hit by bugs that cannot be reproduced across environments, which leads us to set NODE_ENV=production everywhere.