【问题标题】:Node js +Error: listen EADDRINUSE + Unhandled 'error' event节点 js +错误:监听 EADDRINUSE + 未处理的“错误”事件
【发布时间】:2014-02-24 07:20:15
【问题描述】:

我正在使用 eclipse 的 nodeclipse 插件来运行我的节点 js 项目。以下 js 文件工作正常,但 h1 标签 不工作 .我只能看到纯文本。另外我在运行时遇到了这个异常。请帮帮我。

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

【问题讨论】:

    标签: javascript node.js nodeclipse


    【解决方案1】:

    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 视图中看到当前运行的应用程序列表(默认显示在 Node 透视图中)。然后您可以终止选定或全部,重新启动等。

    是的,调试视图不只包括已调试的应用程序。本来应该叫Launch View,但它是Eclipse中的标准View,我们就按它的名字来命名吧。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-07
      • 2018-07-04
      • 2021-09-14
      • 1970-01-01
      • 2019-05-26
      • 2014-01-17
      • 2016-07-12
      • 2014-12-11
      相关资源
      最近更新 更多