user3724677
user3724677

Reputation: 1911

How npm start runs a server on port 8000

I recently used a angular-seed folder from github for angular application development. In some previous angularjs tutorial there was a script folder and a server.js file in the angular-seed folder which had all the configuration for running the node server. So how does npm now just start running a node server and where is all the configuration of that node server?

Upvotes: 182

Views: 669769

Answers (15)

user681
user681

Reputation: 248

You can try below for linux and mac:

PORT=3001 npm start

And below for windows:

set PORT=3001 && npm start

Upvotes: 1

Simmi Mourya
Simmi Mourya

Reputation: 27

You can use,

npm start -- --port 8000

Or if you would like to use environment variables,

PORT=8000 npm start

Upvotes: 0

theocikos
theocikos

Reputation: 1994

To start the port correctly in your desired port use:

npm start -- --port 8000

Upvotes: 154

Shihab Uddin Shakil
Shihab Uddin Shakil

Reputation: 125

npm run start -- -p 8000

8000 is port number you can change your port number

Upvotes: 1

amine2029
amine2029

Reputation: 36

(For those still suffering despite trying all the answers.)

Here is a quick fix that should not be used in production!

Just forward the source port to the target one that you need. Open another shell and tap this command:

socat tcp-listen:8000,reuseaddr,fork tcp:192.168.1.48:3000

In this example; 3000 is the port of the server and 8000 the port you want to forward to (or receive from to be precise)

Enjoy!

Upvotes: 0

Sehrish Waheed
Sehrish Waheed

Reputation: 1555

npm run dev -- --port 3001

npm run on another port in cmd

Upvotes: 10

ibrahim
ibrahim

Reputation: 3

npm start --port 8000 does not work. You should write command like this.

ng serve --port 8000

Upvotes: 0

Soumil Khandelwal
Soumil Khandelwal

Reputation: 190

The solution which will work on every machine, let it be MAC, Window, Linux or any other, just specify the port where you want to run. In your package.json do this :

 "start": "export PORT=3001 && react-scripts start "

Upvotes: 3

Ashish Saini
Ashish Saini

Reputation: 308

Or simply in the terminal

set port=5500 && npm start

Upvotes: 6

Dinesh M
Dinesh M

Reputation: 65

change "start": "react-scripts start", to "start": "set PORT=3001 && react-scripts start",

Upvotes: 6

Ashutosh Singh
Ashutosh Singh

Reputation: 61

npm start -- --port "port number"

Upvotes: 2

Skylin R
Skylin R

Reputation: 2271

You can change the port in the console by running the following on Windows:

SET PORT=8000

For Mac, Linux or Windows WSL use the following:

export PORT=8000

The export sets the environment variable for the current shell and all child processes like npm that might use it.

If you want the environment variable to be set just for the npm process, precede the command with the environment variable like this (on Mac and Linux and Windows WSL):

PORT=8000 npm run start

Upvotes: 81

Kotireddy
Kotireddy

Reputation: 1235

To change the port

npm start --port 8000

Upvotes: 116

YeeHaw1234
YeeHaw1234

Reputation: 2495

We have a react application and our development machines are both mac and pc. The start command doesn't work for PC so here is how we got around it:

"start": "PORT=3001 react-scripts start",
"start-pc": "set PORT=3001&& react-scripts start",

On my mac:

npm start

On my pc:

 npm run start-pc

Upvotes: 150

Mritunjay
Mritunjay

Reputation: 25882

If you will look at package.json file.

you will see something like this

 "start": "http-server -a localhost -p 8000"

This tells start a http-server at address of localhost on port 8000

http-server is a node-module.

Update:- Including comment by @Usman, ideally it should be present in your package.json but if it's not present you can include it in scripts section.

Upvotes: 110

Related Questions