NODE_ENV is not recognised as an internal or external command

前端 未结 3 1207
無奈伤痛
無奈伤痛 2021-01-17 09:38

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 do

相关标签:
3条回答
  • 2021-01-17 10:08

    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"
      },
    
    0 讨论(0)
  • 2021-01-17 10:17

    I can suggest cross platform sollution. It's done with the help of the cross-env npm package. Your script section would look like this:

    "scripts": {
        "globals" : "npm i -g cross-env",
        "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"
      }
    

    So you run once:

    npm run globals // to install global dependencies
    

    Then you're free to use your scripts both on linux and windows(mac?).

    0 讨论(0)
  • 2021-01-17 10:26

    Sometimes this can be fixed by using win-node-env if your running on windows, For using it just run the below command.

    npm install -g win-node-env
    
    0 讨论(0)
提交回复
热议问题