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

后端 未结 30 1392
深忆病人
深忆病人 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:08

    you can use fuser -k 4200/tcp if it is Linux Operating system

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

    Instead of killing the whole process or using ctrl+z, you can simply use ctrl+c to stop the server and can happily use ng serve command without any errors or if you want to run on a different port simply use this command ng serve --port portno(ex: ng serve --port 4201).

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

    When you use Ctrl+Z, you are going to suspend a running task but not to kill it. You can later use command fg to resume the task. If you want to quit ng serve, you should use Ctrl+C instead, in which will also release the 4200 port.

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

    If you compiling your angular JS code in both CMD and IDE then this issue occur. In CMD, your angular JS code compile automatically whenever you change your angular JS code in IDE and then your IDE want to occupy the same port i.e 4200 which is occupied by CMD already So, there is a simple solution for this issue, just close your cmd while compiling your code in IDE.

    0 讨论(0)
  • Use this command to kill ng:

    pkill -9 ng
    
    0 讨论(0)
  • 2020-12-02 04:12

    For Windows:

    Open Command Prompt and

    type: netstat -a -o -n

    Find the PID of the process that you want to kill.

    Type: taskkill /F /PID 16876

    This one 16876 - is the PID for the process that I want to kill - in that case, the process is 4200 - check the attached file.you can give any port number.

    Now, Type : ng serve to start your angular app at the same port 4200

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