节点js +错误:收听EADDRINUSE +未处理的'错误'事件

时间:2014-02-24 07:20:16

标签: javascript node.js nodeclipse

我正在使用 nodeclipse 插件为eclipse运行我的节点js项目。以下js文件工作正常,但 h1 标记无法正常工作。我只能看到一个纯文本.plus我在运行时得到这个异常。请帮助我。

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/');

例外

 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

2 个答案:

答案 0 :(得分:17)

Error: listen EADDRINUSE

此错误表示您已经有另一个进程侦听端口3000。

Here is how to find out which process it is on 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.

答案 1 :(得分:2)

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

  

此错误表示您已经有另一个进程侦听端口3000。

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

是的,Debug View不包括仅调试的应用程序。它应该被命名为Launch View,但它是Eclipse中的标准View,我们将其命名为。

也可以通过关闭其控制台(使用红色方块图标)

来单独终止运行应用程序