Reputation: 553
I'm setting in scripts: "start": "NODE_ENV=development nodemon dist/Server.js"
then trying to read NODE_ENV
in code, both dot and bracket notation return undefined
:
I have next configurations: "@types/node": "^8.0.53" "typescript": "^2.6.1" node 8.9.1 installed locally
Doesn't seems like process.env even have NODE_ENV after I console.log it.
console.log(process.env.NODE_ENV);
console.log(process.env["NODE_ENV"]);
as suggested here
What's wrong with it ?.
Upvotes: 0
Views: 1685
Reputation: 6982
You didn't post how you access the NODE_ENV variable in your code, but this works fine for me:
package.json:
"scripts": {
"test": "NODE_ENV=development nodemon test.js"
}
test.js
console.log(process.env.NODE_ENV)
Result of running npm test
:
[nodemon] 1.12.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node test.js`
development
[nodemon] clean exit - waiting for changes before restart
(I'm using node v7.10.1, but I'd expect this to work on any version)
Upvotes: 1