set node env code example
Example 1: npm node env
require('dotenv').config()
Example 2: set node process production
{
...
"scripts": {
"start": "NODE_ENV=production node ./app"
}
...
}
Example 3: set node process production
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
})
]
Example 4: node how to set environment variable
// get an environment variableexport const token = process.env['API_TOKEN'];// set an environment variable at runtimeprocess.env['RANDOM_ID'] = Math.random();