问题描述
我正在学习angular 2,并且这是我第一次使用angular CLI项目创建一个沙箱项目.
I am learning angular 2 and for the first time I am using the angular CLI project to create a sandbox project.
我能够运行命令"ng serve",并且效果很好.我想停止它的运行,所以我运行了"Control Z".
I was able to run the command "ng serve" and it works great. I wanted to stop it from running so I ran "Control Z".
当我再次尝试运行"ng-serve"命令时,它提示我端口4200已在使用中."
When I tried to run the "ng-serve" command again it gives me "Port 4200 is already in use."
我运行"PS"以获取PID列表,并取消了用于angular-cli的PID,并再次运行"ng-serve",但仍给出了相同的端口使用错误.
I ran "PS" to get a list of the PID and killed the PID for the angular-cli and ran "ng-serve" again still it gives the same port in use error.
推荐答案
这就是我用来终止4200端口上的进度的原因
This is what I used to kill the progress on port 4200
对于Linux用户:
sudo kill $(sudo lsof -t -i:4200)
您也可以尝试以下方法:
You could also try this:
sudo kill `sudo lsof -t -i:4200`
对于Windows用户:
端口号4200已在使用中.以管理员身份打开cmd.在cmd中键入以下命令:
Port number 4200 is already in use. Open the cmd as administrator. Type below command in cmd:
netstat -a -n -o
然后,通过右键单击终端并单击查找来找到端口号为4200的端口,在查找内容"中输入4200,然后单击查找下一个":假设您发现pid 18932使用了端口号4200.在cmd中键入以下命令:
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
对于UNIX:
alias ngf='kill -9 $(lsof -t -i:4200);ng serve'
现在从项目文件夹中的终端中运行 ngf (而不是 ng服务).这将使用端口4200终止所有进程,并运行Angular项目.
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.
这篇关于“端口4200已在使用中".运行ng serve命令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!