0

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 ?.

enter image description here

Sunny
  • 543
  • 10
  • 17

1 Answers1

1

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)

ehrencrona
  • 6,102
  • 1
  • 18
  • 24
  • I know it should work you right. I tried all process.env.NODE_ENV, process.env["NODE_ENV"]. As I know if NODE_ENV not specified it will fall do default `development`, try set test instead of dev, see if it work out for you. – Sunny Nov 20 '17 at 06:57
  • Your example works fine, that something interfering setting env in my code. – Sunny Nov 20 '17 at 07:10