[windows] "NODE_ENV" is not recognized as an internal or external command, operable command or batch file

I'm trying to setup an environment for a Node.js app. but I'm getting this error every time.

"NODE_ENV" is not recognized as an internal or external command, operable command or batch file.

What does this mean and how can I solve this problem?

I'm using Windows and also tried set NODE_ENV=development but had no luck.

This question is related to windows node.js

The answer is


I had the same problem and on windows platform and i just ran the below command

npm install -g win-node-env

and everything works normally


I wrote a module for this: win-node-env.

It creates a NODE_ENV.cmd that sets the NODE_ENV environment variable and spawns a child process with the rest of the command and its args.

Just install it (globally), and run your npm script commands, it should automatically make them work.

npm install -g win-node-env

For those who uses Git Bash and having issues with npm run <script>,

Just set npm to use Git Bash to run scripts

npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe" (change the path according to your installation)

And then npm will run scripts with Git Bash, so such usages like NODE_ENV= will work properly.


Do this it will definitely work

"scripts": {
    "start": "SET NODE_ENV=production && node server"
}

For windows you can do it like

"scripts": {
    "start:prod" : "SET NODE_ENV=production & nodemon app.js",
    "start:dev" : "SET NODE_ENV=development & nodemon app.js"
},

Use win-node-env, For using it just run below command on your cmd or power shell or git bash:

npm install -g win-node-env

After it everything is like Linux.


process.env.NODE_ENV is adding a white space do this

process.env.NODE_ENV.trim() == 'production'

set NODE_ENV=production & nodemon app/app.js

will cause NODE_ENV to contain a space at the end:

process.env.NODE_ENV == 'production'; //false
process.env.NODE_ENV == 'production '; //true

As mentioned in a comment here, use this instead:

NODE_ENV=production&& nodemon app/app.js

If anyone else came here like me trying to find a solution for the error:

'env' is not recognized as an internal or external command

The reason I got this is that I was migrating an angular solution from a mac development machine over to a windows 10 desktop. This is how I resolved it.

  1. run npm install --save-dev cross-env

  2. go into my package.json file and change all the script references from env <whatever> to cross-env <whatever>

Then my commands like: npm run start:some_random_environment_var now run fine on Windows 10.


Changing your scripts to accommodate Windows is a royal pain. Trying to figure out the appropriate Windows translations and maintaining 2 sets of scripts is no way to live your life.

It's much easier to configure npm to use bash on Windows and your scripts will run as is.

Simply run npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe". Make sure the path to the bash executable is correct for your machine. You'll likely need to start a new instance of the terminal for the change to take effect.

The screenshot below illustrates the benefit.

  1. npm ERR! when trying to run script initially.
  2. Script modified for Windows use runs but doesn't show the return message.
  3. After updating npm config to use bash, the script runs and returns the appropriate message.

Getting npm scripts to run as is in Windows


  1. npm install --save-dev "cross-env" module.
  2. modify the code as cross-env NODE_ENV=development node foo.js. Then you can run the like npm run build.

for windows use & in between command also. Like,

  "scripts": {
    "start": "SET NODE_ENV=development & nodemon app/app.js",
  }

Most of the answers up there didn't help me..

What helped me was NODE_ENV=production&& nodemon app/app.js

Take note of the space. Good luck.


npm install -S cross-env

Worked for me


For windows open git bash and try

NODE_ENV=production node app.js


Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`