kvk30
kvk30

Reputation: 1203

Unrecognized PORT command

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

Answers (10)

Ingasha
Ingasha

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

backslashN
backslashN

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

Hassane Jermoune
Hassane Jermoune

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

KARTHIKEYAN.A
KARTHIKEYAN.A

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

sakthi
sakthi

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

Rishabh
Rishabh

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:

in package.json file

Upvotes: 7

mtyson
mtyson

Reputation: 8570

Here's a moronic way I found to recreate this problem:

  1. Create a npm based app on one system
  2. check it out on another system
  3. FAIL to run npm install
  4. run npm start

Receive error described in question.

Upvotes: 0

kvk30
kvk30

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

Mbanda
Mbanda

Reputation: 1018

SET PORT=8090 && nodemon server.js that worked for me

Upvotes: 2

go_gunner
go_gunner

Reputation: 101

  • Install this additional package cross-env in your node environment. The above command you mentioned is Unix (Ubuntu, Mac, etc…). In the windows environment, you need a different syntax and cross-env does your job.
  • You can also create an .env file with

PORT=3006

and save it in your project directory.

Upvotes: 9

Related Questions