nodejs.org
nodejs.org copied to clipboard
Guidelines for treating NODE_ENV in new code
A question of to what value should process.env.NODE_ENV default to if not set, is a quite important one. There is plenty of discussion about it out there, ones advocating 'production' and others 'development'. This can be confusing.
I suggest publishing the following suggestion somewhere in guides chapter.
If process.env.NODE_ENV is undefined, the code should assume default value as follows:
- generic library code:
'development'as the best choice when writing new code; - (server) application code:
'development'because in real life this code is launced by script or loader, explicitly setting the NODE_ENV value; - utility package code:
'production', because it's likely a developer wants to debug his/her own code, not the code of installed npm packages or tools like npm or rimraf.