atom-node-debugger
atom-node-debugger copied to clipboard
node.js NODE_ENV variable always in production (or by default)
I'm attempting to work on a project in Atom for the first time (was using Visual Studio Code up until this point).
I've installed Atom and node-debugger and hit F5. After a few quick changes to my package.json file to point at the right file, the project immediately started. Great! Except it tried to run in my production database (which I (fortunately) didn't have access to).
After some fighting to get it into development mode, I figured it had to be the computer, so I took a clean copy of windows, installed Atom and the package, wrote a 4 line program & it runs in Production mode.
Shouldn't the default of a development environment be development? Or how do I set the environment (not in something that may accidentally be sent to production)?
console.log("start"); var env = process.env.NODE_ENV; console.log(env); console.log("End");
Hi,
This is my understanding of this problem. NODE_ENV is just an environment variable and by default, on a clean machine it is undefined. It seems like your environment sets NODE_ENV to production and that is why you experience this problem. It is easily fixed though since you can define a custom environment for the debugger. The example in the documentation gives:
"node-debugger":
nodePath: "C:/program/nodejs/node.exe"
nodeArgs: "--use-strict --use_inlining"
appArgs: "--arg1=10 --arg2"
debugHost: "192.168.0.20"
debugPort: 5860
env: "key1=value1;key2=value2;key3=value3"
scriptMain: "c:/myproject/main.js"
where env is defining two variables; env1 and env2. In your case I suppose you want to set:
env: "NODE_ENV=development"
Cheers
I've just encountered this too. NODE_ENV is undefined (as @codecontemplator pointed out) by default. When I run node from the cli, that's the case:
$ node
> process.env.NODE_ENV
undefined
but when debugging in Atom, it is set to production by default. Setting it in the env config works fine, but it does seem odd that it's set to production by default.
Just to confirm, my nodePath config is set to the same value as which node.