Reputation: 1203
In my localhost, running below command
PORT=4080 node server.js
But, it was throwing an unexpected error.
'PORT' is not recognized as an internal or external command, operable program or batch file.
Do I need to install any module or did I miss any syntax to run it properly?
Upvotes: 17
Views: 48799
Reputation: 1
Once I realised that the issue is it's a linux command, I switch shells to use Git Bash(I'm using Vs-code) and it worked seamlessly. Hoping this is helpful for a newbie that finds the other suggestions daunting.
Upvotes: 0
Reputation: 2875
Install cross-env
to support all OS.
npm install --save-dev cross-env
or
yarn add -D cross-env
And finally add cross-env to your command in package.json
.
cross-env PORT=4080 node server.js
Upvotes: 1
Reputation: 76
In Windows you can set scripts in package.json:
Delete set PORT=portnumber &&
and keep it like this :
"start": "react-scripts start"
Upvotes: 0
Reputation: 20118
You can try this way also
"scripts": {
"build": "concurrently \"cd client && npm build\" \"cd server && npm build\"",
"install": "(cd client && npm) && (cd server && npm)",
"start": "concurrently \"cd client && SET PORT=3000 && npm start\" \"cd server && SET PORT=3001 && npm start\"",
"start:prod": "cd server && npm start:prod"
}
Upvotes: 0
Reputation: 1
automatically run this port :3000,I tried windows working react
"devDependencies": {
"react-scripts": "0.8.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
Upvotes: 0
Reputation: 129
In Windows you can set scripts in package.json
:
"start": " set PORT=portnumber && react-app-rewired start"
or
"start": " set PORT=3001 && react-script start".
It worked for me:
Upvotes: 7
Reputation: 8570
Here's a moronic way I found to recreate this problem:
npm install
npm start
Receive error described in question.
Upvotes: 0
Reputation: 1203
Apart from cross-env, Below command can serve the purpose.
SET PORT=4080 && node server.js
PS: Set environment variable for nodeJs, run command in project folder.
Upvotes: 38
Reputation: 101
PORT=3006
and save it in your project directory.
Upvotes: 9