“Port 4200 is already in use” when running the ng serve command

后端 未结 30 1389
深忆病人
深忆病人 2020-12-02 03:47

I am learning angular 2 and for the first time I am using the angular CLI project to create a sandbox project.

I was able to run the command \"ng serve\" and it wor

相关标签:
30条回答
  • 2020-12-02 04:17

    VScode terminal in Ubuntu OS use following command to kill process

    lsof -t -i tcp:4200 | xargs kill -9
    
    0 讨论(0)
  • 2020-12-02 04:18

    I am sharing this as the fowling two commands did not do the job on my mac:

    sudo kill $(sudo lsof -t -i:4200)
    
    sudo kill `sudo lsof -t -i:4200`
    

    The following one did, but if you were using the integrated terminal in Visual Code, try to use your machine terminal and add the fowling command:

    lsof -t -i tcp:4200 | xargs kill -9
    
    0 讨论(0)
  • 2020-12-02 04:19

    Right now you can set --port 0 to get a free port.

    ng serve --port 0 // will get a free port for you
    
    0 讨论(0)
  • 2020-12-02 04:20

    This is what I used to kill the progress on port 4200

    For linux users:

    sudo kill $(sudo lsof -t -i:4200)
    

    You could also try this:

    sudo kill `sudo lsof -t -i:4200`
    

    For windows users:

    Port number 4200 is already in use. Open the cmd as administrator. Type below command in cmd:

    netstat -a -n -o
    

    And then, find port with port number 4200 by right click on terminal and click find, enter 4200 in "find what" and click "find next": Let say you found that port number 4200 is used by pid 18932. Type below command in cmd:

    taskkill -f /pid 18932
    

    For UNIX:

    alias ngf='kill -9  $(lsof -t -i:4200);ng serve'
    

    Now run ngf (instead of ng serve) in terminal from the project folder. This will kill all processes using the port 4200 and runs your Angular project.

    0 讨论(0)
  • 2020-12-02 04:20

    In summary there are more than one solution : 1 ) By using another port to define port number ,

    ng serve --open --port 4201
    

    2) by killing the process

    ctrl + c // for kill
    Close all node terminal which is related for running the app.
    

    3) Type

    netstat -a -n -o

    in command prompt then find the related port PID and kill it by

    taskkill /F /PID (pid number)

    4) Type netstat -ano|findstr :4200

    took the foreign address PID which contain the port number and then kill it by

    taskkill /PID (pid number)/F

    0 讨论(0)
  • 2020-12-02 04:21

    For Ubndu 18.04 sudo lsof -t -i tcp:3000 | xargs kill -9

    Its happen when port was unsucessfully terminated so this command will terminat it 4200 or 3000 or3300 any

    0 讨论(0)
提交回复
热议问题