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.
我一直在使用一个节点。几个星期以来,js项目一直运行良好。通常我使用“npm start”来运行我的应用程序,并在localhost(端口3000)的浏览器中查看它。
Today, I started to get the following error while using npm start:
今天在使用npm start时,我开始出现以下错误:
Server started on port 3000
Port 3000 is already in use
I have checked the resource monitor and I have no other process running on port 3000. Why would I be getting this error message?
我检查了资源监视器,在端口3000上没有运行其他进程。为什么我会得到这个错误信息?
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.
在我的app.js中,我有以下代码来设置端口……这是不正确的吗?它以前工作得很好,所以我不确定我做错了什么。
// Set Port
app.set('port', (process.env.PORT || 3000));
app.listen(app.get('port'), function() {
console.log('Server started on port '+app.get('port'));
});
Thanks for the help!
谢谢你的帮助!
EDIT: 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.
编辑:我尝试运行netstat和TCPView来检查使用端口的进程,但是没有使用该端口。我也尝试重新启动我的笔记本电脑,但是我还是得到了同样的错误。
6 个解决方案
#1
26
You can search on how to kill that process.
您可以搜索如何终止这个过程。
For Linux/Mac OS search (sudo) run this in the terminal:
对于Linux/Mac OS搜索(sudo),请在终端中运行:
$ lsof -i tcp:3000
$ kill -9 PID
On Windows:
在Windows上:
netstat -ano | findstr :3000
tskill typeyourPIDhere
change tskill
for taskkill
in git bash
在git bash中更改taskkill的tskill
#2
14
For windows, The Task Manager would definitely show a node process running. Try to kill the process, it will solve the problem.
对于windows,任务管理器肯定会显示正在运行的节点进程。试着终止这个过程,它将解决问题。
#3
5
This happens to me sometimes, EADDR in use. Typically there is a terminal window hiding out in the background that is still running the app. You can stop process with ctrl+C in the terminal window.
这种情况有时发生在我身上,在使用EADDR时。通常有一个隐藏在后台的终端窗口仍在运行。你可以在终端窗口用ctrl+C停止进程。
Or, perhaps you are listening to the port multiple times due to copy/pasta =)
或者,您可能由于copy/通心粉=而多次监听端口)
#4
2
Sometimes it happens, as @sova proposed This happens to me sometimes, EADDR in use. Typically there is a terminal window hiding out in the background that is still running the app. And that's also right with me.
有时它会发生,正如@sova所建议的,有时我也会遇到这种情况,EADDR正在使用。通常情况下,有一个终端窗口隐藏在后台运行这个应用程序,这也对我来说是正确的。
It happens, when you have opened terminal for long time, yeah you have right, you have stop the process. But sometimes it didn't stop in the background. So best solution is that you close the terminal and start it again. It will solves your problem. becuase in my case it works.
当你打开终端很长一段时间,是的,你有权利,你停止了这个过程。但有时它不会停在后台。所以最好的解决办法是关闭终端,然后重新启动。它会解决你的问题。因为在我的情况下它是有效的。
Also,
同时,
sudo lsof -i:<PORT_NO>
close the instance for present time but unable to stop the process in background. So for one time,
暂时关闭实例,但无法在后台停止进程。有一次,
sudo kill <PID>
works, but again when we update our code and save, this problem occurs again as with Nodemon.
可以,但是当我们更新代码并保存时,这个问题再次发生,就像Nodemon一样。
So exit the terminal will solve the problem. OR
所以退出终端会解决这个问题。或
killall -9 node
#5
1
Came from Google here with a solution for High Sierra.
来自谷歌,这里有一个高Sierra的解决方案。
Something changed in the networking setup of macos and some apps (including ping) cannot resolve localhost.
macos的网络设置发生了变化,一些应用程序(包括ping)无法解析localhost。
Editing /etc/hosts seems like a fix:
编辑/etc/hosts似乎可以修复:
cmd: sudo nano /etc/hosts/
content 127.0.0.1 localhost
cmd: sudo nano /etc/hosts/ content 127.0.0.1 localhost
Or simply (if you're sure your /etc/hosts is empty) sudo echo '127.0.0.1 localhost' > /etc/hosts
或者简单地(如果您确定您的/etc/hosts是空的)sudo echo“127.0.0.1 localhost”> /etc/hosts
#6
0
I had the same problem. (The below steps work fine on Windows 10):
我也有同样的问题。(以下步骤适用于Windows 10):
- Open Task manager (press Ctrl+Alt+Delete)
- 打开任务管理器(按Ctrl+Alt+Delete)
- Select the 'Processes tab'
- 选择“进程选项卡”
- Search for 'Node.js: Server-side JavaScript'
- 搜索的节点。js:服务器端JavaScript
- Select it and click on 'End task' button
- 选择它并单击“结束任务”按钮。
Now you can run npm start
.
现在可以运行npm start了。
Hope it helps you.
希望它能帮助你。
#1
26
You can search on how to kill that process.
您可以搜索如何终止这个过程。
For Linux/Mac OS search (sudo) run this in the terminal:
对于Linux/Mac OS搜索(sudo),请在终端中运行:
$ lsof -i tcp:3000
$ kill -9 PID
On Windows:
在Windows上:
netstat -ano | findstr :3000
tskill typeyourPIDhere
change tskill
for taskkill
in git bash
在git bash中更改taskkill的tskill
#2
14
For windows, The Task Manager would definitely show a node process running. Try to kill the process, it will solve the problem.
对于windows,任务管理器肯定会显示正在运行的节点进程。试着终止这个过程,它将解决问题。
#3
5
This happens to me sometimes, EADDR in use. Typically there is a terminal window hiding out in the background that is still running the app. You can stop process with ctrl+C in the terminal window.
这种情况有时发生在我身上,在使用EADDR时。通常有一个隐藏在后台的终端窗口仍在运行。你可以在终端窗口用ctrl+C停止进程。
Or, perhaps you are listening to the port multiple times due to copy/pasta =)
或者,您可能由于copy/通心粉=而多次监听端口)
#4
2
Sometimes it happens, as @sova proposed This happens to me sometimes, EADDR in use. Typically there is a terminal window hiding out in the background that is still running the app. And that's also right with me.
有时它会发生,正如@sova所建议的,有时我也会遇到这种情况,EADDR正在使用。通常情况下,有一个终端窗口隐藏在后台运行这个应用程序,这也对我来说是正确的。
It happens, when you have opened terminal for long time, yeah you have right, you have stop the process. But sometimes it didn't stop in the background. So best solution is that you close the terminal and start it again. It will solves your problem. becuase in my case it works.
当你打开终端很长一段时间,是的,你有权利,你停止了这个过程。但有时它不会停在后台。所以最好的解决办法是关闭终端,然后重新启动。它会解决你的问题。因为在我的情况下它是有效的。
Also,
同时,
sudo lsof -i:<PORT_NO>
close the instance for present time but unable to stop the process in background. So for one time,
暂时关闭实例,但无法在后台停止进程。有一次,
sudo kill <PID>
works, but again when we update our code and save, this problem occurs again as with Nodemon.
可以,但是当我们更新代码并保存时,这个问题再次发生,就像Nodemon一样。
So exit the terminal will solve the problem. OR
所以退出终端会解决这个问题。或
killall -9 node
#5
1
Came from Google here with a solution for High Sierra.
来自谷歌,这里有一个高Sierra的解决方案。
Something changed in the networking setup of macos and some apps (including ping) cannot resolve localhost.
macos的网络设置发生了变化,一些应用程序(包括ping)无法解析localhost。
Editing /etc/hosts seems like a fix:
编辑/etc/hosts似乎可以修复:
cmd: sudo nano /etc/hosts/
content 127.0.0.1 localhost
cmd: sudo nano /etc/hosts/ content 127.0.0.1 localhost
Or simply (if you're sure your /etc/hosts is empty) sudo echo '127.0.0.1 localhost' > /etc/hosts
或者简单地(如果您确定您的/etc/hosts是空的)sudo echo“127.0.0.1 localhost”> /etc/hosts
#6
0
I had the same problem. (The below steps work fine on Windows 10):
我也有同样的问题。(以下步骤适用于Windows 10):
- Open Task manager (press Ctrl+Alt+Delete)
- 打开任务管理器(按Ctrl+Alt+Delete)
- Select the 'Processes tab'
- 选择“进程选项卡”
- Search for 'Node.js: Server-side JavaScript'
- 搜索的节点。js:服务器端JavaScript
- Select it and click on 'End task' button
- 选择它并单击“结束任务”按钮。
Now you can run npm start
.
现在可以运行npm start了。
Hope it helps you.
希望它能帮助你。