What’s the use of node’s NODE_ENV?

  node.js, question

What’s the use of solving this environmental variable?

viaNODE_ENVYou can set environment variables (default isdevelopment)。
Generally, we check this value to treat the development environment and the production environment differently. You can set this value on the command line in the following way:

  • linux & mac:export NODE_ENV=production
  • windows:set NODE_ENV=production

For example, if the code is to do some processing in the production environment, it can be written as follows:

if (process.env.NODE_ENV === 'production') {
 // just for production code
 bracket