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

use*_*153 3 node.js

我是一名初学程序员,正在尝试使用以下教程网站http://www.nodebeginner.org/#hello-world学习node.js

我到了试图设置服务器的地步,但是下面的代码出错了

var http = require("http");

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

错误:

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)
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激

Pau*_*aul 15

EADDRINUSE表示地址正在使用中.

基本上,您尝试同时启动两个使用端口8888的服务器.您必须在启动另一个服务器之前停止或终止它们.端口8888上的另一个服务器可能是运行节点脚本的另一个进程,或者它可能是系统中用于在端口8888上提供内容的其他服务器.

或者,如果在终止旧服务器后没有让套接字稳定几秒钟,您可以得到此信息.