2014-02-24 100 views
11

我使用nodeclipse Eclipse插件運行我的js節點js的project.Following文件工作正常,但H1標籤不工作。我只能看到一個純文本text.plus我得到這個異常在runtime.please幫助我。節點JS +錯誤:聽EADDRINUSE +未處理的「錯誤」事件

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 

回答

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

+1請確保您在你的答案的步驟來終止。如果鏈接改變或內容改變,這個答案可能變得不那麼有用。 – thefourtheye

+0

並不認爲這是必要的,因爲它與問題沒有直接關係,而是附加說明。 – Patrick

2

正如帕特里克說Error: listen EADDRINUSE

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

如果使用Nodeclipse運行Node.js應用程式,你可以看到目前在調試視圖中運行的應用程序列表(默認情況下顯示節點透視)。然後您可以終止選定或全部,重新啓動等。

是的,Debug View不包括僅調試的應用程序。它應該被命名爲Launch View,但它是Eclipse中的標準View,我們將它命名爲它。

而且正在運行的應用可以分別通過關閉它的控制檯(用紅色方框)