Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NODE_ENV is not recognised as an internal or external command

Tags:

I am developing in node.js and wanted to take into account both production and development environment. I found out that setting NODE_ENV while running the node.js server does the job. However when I try to set it in package.json script it gives me the error:

NODE_ENV is not recognised as an internal or external command

Below is my package.json

{
  "name": "NODEAPT",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "NODE_ENV=development node ./bin/server",
    "qa2": "NODE_ENV=qa2  node ./bin/server",
    "prod": "NODE_ENV=production node ./bin/server"
  },
  "dependencies": {
    "body-parser": "~1.15.1",
    "cookie-parser": "~1.4.3",
    "debug": "~2.2.0",
    "express": "~4.13.4",
    "fs": "0.0.1-security",
    "jade": "~1.11.0",
    "morgan": "~1.7.0",
    "oracledb": "^1.11.0",
    "path": "^0.12.7",
    "serve-favicon": "~2.3.0"
  }
}

I run my node server as: npm run qa2 for example.

I don't know what I am doing wrong. Any help is appreciated

like image 393
Shubham Khatri Avatar asked Oct 14 '16 03:10

Shubham Khatri


People also ask

Can I override NODE_ENV?

NODE_ENV cannot be overridden manually, which can help keep developers from deploying a slow development build to production by accident.

What does NODE_ENV mean?

NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).

What does NODE_ENV default to?

We see that it in fact reads NODE_ENV and defaults to 'development' if it isn't set. This variable is exposed to applications via 'app. get(“env”)' and can be used to apply environment specific configurations as explained above, but it's up to you to use this or not.


1 Answers

Since you are using windows operating system., the command varies from the unix system command that you are using.

In windows you have to modify you script as.

"scripts": {
    "start": " SET NODE_ENV=development &  node ./bin/server",
    "qa2": "SET NODE_ENV=qa2 & node ./bin/server",
    "prod": "SET NODE_ENV=production & node ./bin/server"
  },

Use SET and then an & after that.

However using cross-env npm package for cross platform stability is recommeded.

Install it like npm install -S cross-env

"scripts": {
    "start": " cross-env NODE_ENV=development &  node ./bin/server",
    "qa2": "cross-env NODE_ENV=qa2 & node ./bin/server",
    "prod": "cross-env NODE_ENV=production & node ./bin/server"
  },
like image 111
Jagrati Avatar answered Oct 13 '22 01:10

Jagrati