Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make npm start script run ng serve in a particular port

I have some scripts in my package.json, and I need to know how to get the start script to correctly accept the -port parameter for angular-cli.

  "scripts": {
    "ng": "ng",
    "start": "ng serve  --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

We need this because we would like to run multiple instances of our software simultaneously. Currently, if I have one project running on the default port 4200, and try to run npm start -port 4300 in a second terminal window, I get, "Port 4200 is already in use. Use '--port' to specify a different port."

What can I do to get my build to run in a particular port? And how can I make it so that I can pass the port number into the npm start script from the command line?

like image 616
BBaysinger Avatar asked Nov 07 '17 19:11

BBaysinger


People also ask

What port does npm start run on?

The next time you run the npm start command, the default port used will be 7200 .

Is npm start same as NG serve?

npm start runs an arbitrary command specified in the package's "start" property of its "scripts" object. If no "start" property is specified on the "scripts" object, it will run node server. js. It seems like ng serve starts the embedded server whereas npm start starts the Node servers.


1 Answers

If you add "--" the parameters are passed through:

npm start -- --port 4301
like image 77
Cocaux Avatar answered Sep 19 '22 22:09

Cocaux