我的节点服务器出现问题。我正在尝试从我的coffees.js文件中收集数据,该文件位于路径文件夹中,方法是将其链接到我的server.js文件。我的server.js文件和包含coffees.js文件的routes文件夹都在我的nodeservers文件夹中。当我运行server.js(这可能是我认为编码错误的问题)时,我收到以下错误:
服务器运行在http-00000000:8080 / 听8080端口......
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 Server.listen (net.js:1138:5)
at Function.app.listen (/node_modules/express/lib/application.js:533:24)
at Object.<anonymous> (/home/ec2-user/nodeservers/simpleserver.js:19:5)
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)
[ec2-user@ip-10-74-151-139 nodeservers]$ ^C
[ec2-user@ip-10-74-151-139 nodeservers]$
我的simpleserver.js文件如下所示:
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8080);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8080/");
var express = require('express'),
coffees = require('./routes/coffees');
var app = express();
app.get('/coffees', coffees.findAll);
app.get('/coffees/:id', coffees.findById);
app.listen(8080);
console.log('Listening on port 8080...');
任何人都能告诉我什么是错的?
答案 0 :(得分:0)
删除
server.listen(8080)
或app.listen(8080)
。
我认为你想使用express,所以删除第一个。