简体   繁体   English

node.js代码示例教程失败,错误:listen EADDRINUSE

[英]tutorial of node.js code sample fails with Error: listen EADDRINUSE

I am a beginner programmer that is trying to learn node.js using the following tutorial site http://www.nodebeginner.org/#hello-world 我是一名初学程序员,正在尝试使用以下教程网站http://www.nodebeginner.org/#hello-world学习node.js

I got to the point where I was trying to set up the server but got an error with the below code 我到了试图设置服务器的地步,但是下面的代码出错了

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}).listen(8888);

error: 错误:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:884:11)
    at Server._listen2 (net.js:1022:14)
    at listen (net.js:1044:10)
    at Server.listen (net.js:1110:5)
    at Object.<anonymous> (/Users/.........../server.js:7:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

any help would be appreciated 任何帮助,将不胜感激

EADDRINUSE means that address is in use. EADDRINUSE表示地址正在使用中。

Basically, you tried to start two servers at the same time that both use port 8888. You have to stop or kill one before starting another. 基本上,您尝试同时启动两个使用端口8888的服务器。您必须在启动另一个服务器之前停止或终止它们。 The other server on port 8888 could be another process running your node script, or it could be something else in the system that serves content on port 8888. 端口8888上的另一个服务器可能是运行节点脚本的另一个进程,或者它可能是系统中用于在端口8888上提供内容的其他服务器。

Alternatively, you can get this if you don't let the socket settle for a few seconds after terminating the old server. 或者,如果在终止旧服务器后不让套接字静置几秒钟,则可以获得此信息。

A more practical answer based on this great one . 基于这个伟大的答案的更实际的答案。

Find out what is using port 8888 with this command: 使用此命令找出使用端口8888的内容:

lsof -i tcp:8888

You should get something like this: 你应该得到这样的东西:

COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    86456   myName   13u  IPv6 0xa6b50fb47c9c3c81      0t0  TCP *:ddi-tcp-1 (LISTEN)

Now that you know which process is in the way, KILL IT! 既然你知道哪个过程在路上,那就杀了! Softly, like so: 轻轻地,像这样:

kill -15 86456

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM