0

I define environment variable in npm script.

"scripts": {
    "start:build": "tsc -w",
    "start:live": "tsc",
    "start:run": "nodemon build/server.js",
    "start:dev:windows": "SET NODE_ENV=production && concurrently npm:start:build npm:start:run",
    "seeding": "node build/seeding.js"
  },

But when I retrieve this NODE_ENV it is available but return false when I compare with same string.

console.log('NODE_ENV', process.env.NODE_ENV, process.env.NODE_ENV == 'production');

Below is attached snapshot of my terminal

Output of of my terminal

Charlie
  • 22,886
  • 11
  • 59
  • 90
Ameer Hamza
  • 141
  • 1
  • 15
  • Does this answer your question? [How to set environment variables from within package.json?](https://stackoverflow.com/questions/25112510/how-to-set-environment-variables-from-within-package-json) – Henrik Erstad Jun 11 '21 at 07:21
  • No this question does not satisficed – Ameer Hamza Jun 11 '21 at 07:24

1 Answers1

2

The entry in the package json adds a space to the end of the value production. It is actually production (notice the space). The && symbol should touch the end of the value.

In the image you have attached, you can see there are two spaces right after the second string of your console.log result. This is why the third console.log entry return false - because, you try to compare it without the space trailing it.

Correct line:

"SET NODE_ENV=production&&concurrently npm:start:build npm:start:run"
Charlie
  • 22,886
  • 11
  • 59
  • 90
  • Ptoblem is, we have 5 devs with windows machines and only 1 of them have the problem. I am assuming this is a Git Bash problem? – Michael Bruce Sep 09 '21 at 16:48
  • It should be. If the files are identical, they should behave the same. Check the Node version too. – Charlie Sep 09 '21 at 16:52