Node.js 端口 3000 已在使用中,但实际上并未使用? [英] Node.js Port 3000 already in use but it actually isn't?

查看:27
本文介绍了Node.js 端口 3000 已在使用中,但实际上并未使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 node.js 项目已经有几周时间了,而且效果很好.通常,我使用 npm start 来运行我的应用程序并在本地主机的浏览器中查看它,端口为 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 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) run 在终端中:

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 

在 git bash 中将 tskill 更改为 taskkill

这篇关于Node.js 端口 3000 已在使用中,但实际上并未使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆