错误:听EADDRINUSE

时间:2015-01-13 16:54:26

标签: javascript node.js express

我收到以下错误:

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     (C:\Users\mississauga\OneDrive\workspace\Editor\node_modules\express\lib\application.js:533:24)
at Object.<anonymous> (C:\Users\mississauga\OneDrive\workspace\Editor\bin\www:7:18)
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)

我尝试将端口从3000更改为8000,仍然出现相同的错误。我关闭程序并重新启动我的笔记本电脑,然后尝试运行该程序,我仍然得到相同的错误。我用了这个tutorial。我的代码与教程非常相似。我的程序运行正常,但是当我使用socket.io时出现错误,我删除了socket.io代码,并用旧的工作代码替换它们,除了现在我的旧代码不起作用。

这是我的代码。

app.js

var express = require('express');
var http = require('http');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var Parse = require('parse').Parse;
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
TwitterStrategy = require('passport-twitter');
GoogleStrategy = require('passport-google');
FacebookStrategy = require('passport-facebook');
var routes = require('./routes');
var expressSession = require('express-session');
var users = require('./routes/user');
var flash = require('connect-flash');
var app = express();
var User = require('./Models/users.js')

// view engine setup
app.set('views', path.join(__dirname, '/views'));
app.set('view engine', 'jade');

app.use(favicon());
app.use(flash());
app.use(logger('dev'));
app.use(bodyParser());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(expressSession({
secret:'Cortana',
resave: true,
saveUninitialized: true
}));

app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);

mongoose.connect('mongodb://blanksiadmin:Db6263779294@ds062097.mongolab.com:62097/users');
var conn = mongoose.connection;

var initPassport = require('./passport/init');
initPassport(passport);

var routes = require('./routes/index')(passport);
app.use('/', routes);

//mongoose.set('debug', true);
/// catch 404 and forwarding to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
err.message;
next(err);
});


// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
    res.render('error', {
        message: err.message,
        error: err
    });
});
};


 // production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.render('error', {
    message: err.message,
    error: {}
});
});
conn.once('open', function(){
  console.log("connection Open");
})



module.exports = app;

WWW:

#!/usr/bin/env node
var debug = require('debug')('my-application');
var app = require('../app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

0 个答案:

没有答案