简体   繁体   中英

Can't run npm start command (Node.js)

I have a npm start script like this:

"start": "NODE_ENV=development PORT=3003 nodemon app.js",

but when I run it I get the following output:

'NODE_ENV' is not recognized as an internal or external command,

I am using vscode with powershell, anyone know why this doesn't work?

Use

SET NODE_ENV=development
PORT=3003
nodemon app.js

for windows. The one you tried works for Linux

This command works fine on linux, but windows does not recognize the NODE_ENV command. to fix this install this package globally:

npm install -g win-node-env

see win-node-env

This command works fine in linux, for windows use:-

  "start": "set NODE_ENV=development&&PORT=3003&&nodemon app.js"

Install cross-env as dev dependency which run scripts that set and use environment variables across platforms

npm i cross-env -D

Change to this:

"start": "cross-env NODE_ENV=development PORT=3003 nodemon app.js"

Best solution will be to use dotenv to save environment variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM