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

2

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

2 Comments

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?
It should be. If the files are identical, they should behave the same. Check the Node version too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.