发生未处理的异常:端口4200已在使用中使用'--port'指定其他端口

问题描述

I tried to access localhost:4200 on my browser for my project. And the compile error message showed up each time I opened localhost4200. It says port 4200 is already in use. I tried online method like Ctrl+C but it doesn't work and have the error message shows up again. Could you help me with this problem? Thanks! The first screenshot is what my browser web page looks like when I go to localhost 4200.

This is what showed me in the terminal window after I run npm start. I could not run ng serve for some reasons. But the npm start works fine for me before.

解决方法

您可以使用以下方法杀死端口:

kill $(lsof -ti:4200)

然后再次运行ng serve

尽管您有两个很可能没有连接的不同问题。您在浏览器中看到的错误是由于代码错误所致,我们需要更多信息来帮助您进行修复。

,

这是在我的档案中。如何杀死Windows机器上的所有节点进程? taskkill /F /IM node.exe

这是另一种方法。

killall node

,

如果您使用Windows,则可以使用netstat -ano | findstr 4200获取pid 那么您可以使用taskkill / f / t / im yourpid关闭4200端口,然后重新启动它。希望它可以为您提供帮助

,

您可以杀死4200上运行的任务,也可以只使用ng serve --port 4201