我已经用了几个星期的node.js项目,它一直工作的很好。通常,我使用npm start
运行我的应用程序,并在本地主机端口3000上的浏览器中查看它。
今天,我开始在使用npm时得到以下错误:
Server started on port 3000
Port 3000 is already in use
我已经检查了资源监视器,并且没有其他进程运行在端口3000上。为什么我会收到这条错误消息?
在我的app.js中,我有以下代码将port...is设置为不正确?它以前很好,所以我不知道我做错了什么。
// 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来检查哪个进程正在使用端口,但是没有什么使用该端口。我也尝试重新启动我的笔记本电脑,但我仍然会遇到同样的错误。
发布于 2020-01-20 05:30:11
我在使用带有nodemon的快速服务器在NodeJS上。我收到了以下消息,这似乎是个错误:
$ node ./bin/www
Port 3000 is already in use
如果终止所有节点服务器连接,则可以在package.json文件中添加以下代码:
"scripts": {
"start": "node ./bin/www",
"stop": "taskkill -f -im node.exe"
},
此外,我还找到了一些解决方案-- windows命令和Win 10 x64上的bash。
我所有的笔记都在这里:
#终止所有NodeJS服务器连接
$ taskkill -f -im node.exe
SUCCESS: The process "node.exe" with PID 14380 has been terminated.
SUCCESS: The process "node.exe" with PID 18364 has been terminated.
SUCCESS: The process "node.exe" with PID 18656 has been terminated.
#示例:打开Windows,在node.exe上查看"node.exe“PID数字
>> Command Line
$ netstat /?
$ netstat -a -n -o
$ netstat -ano
#通过端口号(示例)杀死Windows中的进程
求救:
$ taskkill /?
$ tskill /?
代码1:
$ taskkill -pid 14228
ERROR: The process with PID 14228 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
代码2:
$ taskkill -f -pid 14228
SUCCESS: The process with PID 14228 has been terminated.
代码3:
$ tskill 14228
#命令行,用于查看特定端口
(Cmd):
$ netstat -ano | find "14228"
in bash:
$ netstat -ano | grep "14228" or $ netstat -ano | grep 14228
使用“任务列表”命令#查找node.exe
(Cmd):
$ tasklist | find "node"
in bash:
$ tasklist | grep node
$ tasklist | grep node.exe
node.exe 14228 Console 2 48,156 K
node.exe 15236 Console 2 24,776 K
node.exe 19364 Console 2 24,428 K
https://stackoverflow.com/questions/39322089
复制相似问题