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.
-
This issue is that isn't how you set environmental variables within the PowerShell CLI. See: docs.microsoft.com/en-us/powershell/module/…– undefinedSep 26, 2021 at 10:32
1 Answer
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
-
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. Sep 26, 2021 at 12:47 -
@MohammadAliShuvo please mark the answer if it's solves your problem Nov 30, 2021 at 3:37