Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

javascript - Node.js端口3000已在使用中,但实际上不是吗?(Node.js Port 3000 already in use but it actually isn't?)

I have been working with a node.js project for a few weeks and it has been working great.(我已经在一个node.js项目上工作了几周,并且运行良好。)

Usually I use 'npm start' to run my app and view it in a browser at on localhost, port 3000.(通常,我使用“ npm start”运行我的应用程序,并在浏览器上的本地主机端口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?(在我的app.js中,我有以下代码来设置端口...这不正确吗?) 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')); }); 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.(编辑:我已经尝试运行netstat和TCPView来检查正在使用该端口的进程,但是没有使用该端口的任何东西。) I also tried restarting my laptop but I still get the same error.(我也尝试过重新启动笔记本电脑,但仍然出现相同的错误。)   ask by user2573690 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can search on how to kill that process.(您可以搜索如何终止该进程。)

For Linux/Mac OS search (sudo) run this in the terminal:(对于Linux / Mac OS搜索(sudo) run ,请在终端中(sudo) run(sudo) run :) $ 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中将tskill更改为taskkill)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...