server_02.js:
var http = require("http");
function start() {
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.");
}
exports.start = start;
index.js:
var server = require("./server_02");
server.start();
抛出错误:
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8888
我哪里错了? 我正在为初学者o.O
撰写一本简单的书籍指南答案 0 :(得分:1)
这意味着其他一些进程已经在侦听该端口。如果您使用的是* nix,则可以尝试执行sudo netstat -nlp | grep 8888
之类的内容。