Node.js Port 3000已经在使用但实际上并没有? [英] Node.js Port 3000 already in use but it actually isn't?
问题描述
我一直在使用node.js项目几个星期,它一直很好用。通常我使用'npm start'来运行我的应用程序并在浏览器上的localhost,端口3000上查看它。
I have been working with a node.js project for a few weeks and it has been working great. Usually I use 'npm start' to run my app and view it in a browser at on localhost, port 3000.
今天,我在使用时开始出现以下错误npm start:
Today, I started to get the following error while using npm start:
Server started on port 3000
Port 3000 is already in use
我检查了资源监视器,我没有在端口3000上运行其他进程。为什么我会得到这个错误信息?
I have checked the resource monitor and I have no other process running on port 3000. Why would I be getting this error message?
在我的app.js中,我有以下代码来设置端口......这是不正确的?它之前工作正常,所以我不确定我做错了什么。
In my app.js I have the following code to set the port...is this incorrect? It worked fine before so I'm not sure what I am doing wrong.
// Set Port
app.set('port', (process.env.PORT || 3000));
app.listen(app.get('port'), function() {
console.log('Server started on port '+app.get('port'));
});
感谢您的帮助!
编辑:
我尝试运行netstat和TCPView来检查使用该端口的进程,但没有使用该端口。我也试过重启我的笔记本电脑,但我仍然得到同样的错误。
I have tried running netstat and TCPView to check what process is using the port, but there is nothing using that port. I also tried restarting my laptop but I still get the same error.
推荐答案
您可以搜索如何终止该过程。
You can search on how to kill that process.
对于 Linux / Mac 操作系统搜索(sudo)在终端中运行
这个:
For Linux/Mac OS search (sudo) run
this in the terminal:
$ lsof -i tcp:3000
$ kill -9 PID
在Windows上:
netstat -ano | findstr :3000
tskill typeyourPIDhere
更改 tskill
for taskkill
in git bash
change tskill
for taskkill
in git bash
这篇关于Node.js Port 3000已经在使用但实际上并没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!