javascript Node js +Error: 监听 EADDRINUSE + 未处理的“错误”事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21981295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:08:40  来源:igfitidea点击:

Node js +Error: listen EADDRINUSE + Unhandled 'error' event

javascriptnode.jsnodeclipse

提问by Amila Iddamalgoda

I'm using nodeclipseplugin for eclipse to run my node js project.Following js file is working properly but h1tag is not working.I can only see a plain text.plus I'm getting this exception in the runtime.please help me out.

我正在使用Eclipse 的 nodeclipse插件来运行我的节点 js 项目。以下 js 文件工作正常,但h1标签不起作用。我只能看到纯文本。加上我在运行时遇到此异常。请帮助我出去。

javascript file

javascript文件

   var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/html'});
    response.end('<html><body><h1>Home</h1> URL was: ' + request.url + '</body></html>');
}).listen(3000, 'localhost');

console.log('Server running at http://localhost:3000/');

exception

例外

 events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:904:11)
    at Server._listen2 (net.js:1042:14)
    at listen (net.js:1064:10)
    at net.js:1146:9
    at dns.js:72:18
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:902:3

回答by Patrick

Error: listen EADDRINUSE

Error: listen EADDRINUSE

This error means that you already have another process listening on port 3000.

此错误意味着您已经有另一个进程在侦听端口 3000。

Here is how to find out which process it is on windows

以下是如何找出它在 Windows 上的进程

C:\> netstat -a -b
(add -n to stop it trying to resolve hostnames, which will make it a lot faster)

Edit: +1 for Dane's recommendation for TCPView. Looks very useful!

-a Displays all connections and listening ports.

-b Displays the executable involved in creating each connection or listening port. In some cases well-known executables host multiple independent components, and in these cases the sequence of components involved in creating the connection or listening port is displayed. In this case the executable name is in [] at the bottom, on top is the component it called, and so forth until TCP/IP was reached. Note that this option can be time-consuming and will fail unless you have sufficient permissions. -n Displays addresses and port numbers in numerical form.

回答by Paul Verest

As Patrick has said Error: listen EADDRINUSE

正如帕特里克所说 Error: listen EADDRINUSE

This error means that you already have another process listening on port 3000.

此错误意味着您已经有另一个进程在侦听端口 3000。

If you used Nodeclipse to run Node.js application, you can see list of currently running apps in Debug View (shown by default in Node perspective). Then you can terminate selected or all, restart etc.

如果您使用 Nodeclipse 运行 Node.js 应用程序,您可以在调试视图中看到当前正在运行的应用程序列表(默认显示在节点透视图中)。然后您可以终止选定或全部,重新启动等。

Yes, Debug View does not includes only debugged apps. It should have been named Launch View, but it is standard View in Eclipse, we name it as it is named.

是的,调试视图不仅仅包括调试过的应用程序。它应该被命名为Launch View,但它是Eclipse中的标准View,我们就如其名一样命名。

Also running apps can be terminated individually by closing its Console (using red square icon)

还可以通过关闭其控制台来单独终止正在运行的应用程序(使用红色方块图标)