web-dev-qa-db-ja.com

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

Eclipse用のnodeclipseプラグインを使用してノードjsプロジェクトを実行しています。次のjsファイルは正常に機能していますが、h1タグは機能していません。Iプレーンテキストしか表示されません。さらに、ランタイムでこの例外が発生します。手伝ってください。

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
11

Error: listen EADDRINUSE

このエラーは、ポート3000でリッスンしている別のプロセスがすでに存在することを意味します。

これが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.
17
Patrick

パトリックが言ったようにError: listen EADDRINUSE

このエラーは、ポート3000でリッスンしている別のプロセスがすでに存在することを意味します。

Nodeclipseを使用してNode.jsアプリケーションを実行した場合、現在実行中のアプリのリストをデバッグビューで確認できます(デフォルトではNodeパースペクティブ)に表示されます)。次に、選択したものまたはすべてを終了したり、再起動したりできます。 。

はい、デバッグビューにはデバッグされたアプリだけが含まれているわけではありません。 Launch Viewという名前にする必要がありますが、Eclipseの標準ビューであるため、名前を付けたとおりに名前を付けます。

また、実行中のアプリは、コンソールを閉じることで個別に終了できます(赤い四角のアイコンを使用)

2
Paul Verest