I want to set some env variable in my node app but when I run this command NODE_ENV=development x=23 nodemon.cmd server.js
then it gives me that error NODE_ENV=development' is not recognized, I found some solution where it said that I have to run a
npm package
npm install -g win-node-env
then it will work, but in my case, I got the same error. I am a windows user, any solution how to fix this.
Asked
Active
Viewed 5,223 times
1

Mohammad Ali Shuvo
- 35
- 1
- 7
-
This issue is that isn't how you set environmental variables within the PowerShell CLI. See: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables – undefined Sep 26 '21 at 10:32
1 Answers
2
This may or may not relevant to your question, but as far as I know, windows powershell syntax does not assign variable that way.
to assign variable in windows, you can subtitute NODE_ENV=development
with $NODE_ENV:development
As a workaround, and if you want to run it on any OS, use cross-env
npm package.
npm install --save-dev cross-env
Now, it can run command such as:
cross-env NODE_ENV=development node server.js

Jastria Rahmat
- 776
- 1
- 6
- 27
-
Thanks for your reply, I install the cross-env package and and run `cross-env NODE_ENV=development nodemon server.js` but it showes that it is not recognized but using Command Prompt solve my problem. – Mohammad Ali Shuvo Sep 26 '21 at 12:47
-
@MohammadAliShuvo please mark the answer if it's solves your problem – Jastria Rahmat Nov 30 '21 at 03:37