It is vague how many ways to set NODE_ENV

I am trying to set a flag that tells my code whether it is in production or development. So far I have seen:

In the VS code launch.json:

{ "configurations": { "env": "NODE_ENV": "development" } }

In Node package.json:

{ "scripts": { "start": "NODE_ENV=production" } }

In webpack webpack.config.js:

module.exports = { "plugins": new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }) }

When running the code:

set NODE_ENV=production && node app

NPM packages:

https://www.npmjs.com/package/envify

Powershell:

$env:NODE_ENV="production"

I think I'm just confused, because by default I have about 4 of these sets. How exactly do they interact? Do they all refer to the same variable? Should I have only one of them? Which of them overwrite the rest?

, , , , , . , , ?

+4
1

NODE_ENV , . . wikipedia.

Unix Unix- . , , , , . API fork exec. , , bash, , env ENVIRONMENT_VARIABLE=VALUE <command>. Unix, DOS Windows ; . .

, pm2, pm2 NODE_ENV . JSON , , env.

, NODE_ENV , , .

(), .

+1

All Articles