“NODE_ENV” is not recognized as an internal or external command, operable command or batch file

后端 未结 16 1496
清歌不尽
清歌不尽 2020-11-29 15:33

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 extern

相关标签:
16条回答
  • 2020-11-29 16:00
    npm install -S cross-env
    

    Worked for me

    0 讨论(0)
  • 2020-11-29 16:00

    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"
    },
    
    0 讨论(0)
  • 2020-11-29 16:03

    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
    
    0 讨论(0)
  • 2020-11-29 16:03
    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
    
    0 讨论(0)
  • 2020-11-29 16:03

    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.

    0 讨论(0)
  • 2020-11-29 16:04

    It sounds like your error comes from an attempt to run something like this (which works in Linux)

    NODE_ENV=development node foo.js
    

    the equivalent in Windows would be

    SET NODE_ENV=development
    node foo.js
    

    running in the same command shell. You mentioned set NODE_ENV did not work, but wasn't clear how/when you executed it.

    0 讨论(0)
提交回复
热议问题