I am trying to use the NODE_DEV environment variable within my javascript application run specific code conditionally. I therefor set variable inside my script definition, which I later use like this: npm run dev.
However my function isDevelopment() always returns false, though outputting process.env.NODE_ENV correctly returns development. I have no idea what is wrong with my comparsion. I have tried all kinds of combination, like ', ", ==, === without luck.
What am I doing wrong here?
package.json
{
// ...
"scripts": {
// ...
"dev": "set NODE_ENV=development && npx npm-run-all --parallel run_nodemon run_browser-sync",
// ...
},
// ...
}
app.js
function isDevelopment() {
console.log(process.env.NODE_ENV); // outputs as expected: development
return process.env.NODE_ENV === "development";
}
console.log(isDevelopment()); // outputs: false