如何解决未处理的错误事件在快速服务器中侦听EADDRINUSE 127.0.0.1:3000

时间:2016-08-18 19:28:47

标签: node.js mongodb express

我检查过,如果任何其他进程正在使用节点3000.但事实并非如此。它早先工作正常,但现在我一次又一次地得到这个错误。我的mongodb服务器运行正常。

C:\Users\APOORVA\Desktop\Coursera\rest-server>npm start

> rest-server@0.0.0 start C:\Users\APOORVA\Desktop\Coursera\rest-server
> node ./bin/www

Server running at http://localhost:3000/
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE 127.0.0.1:3000
    at Object.exports._errnoException (util.js:1007:11)
    at exports._exceptionWithHostPort (util.js:1030:20)
    at Server._listen2 (net.js:1253:14)
    at listen (net.js:1289:10)
    at net.js:1399:9
    at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:65:16)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:84:10)

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "F:\\from C drive_do not delete\\nodejs\\node.exe" "F:\\from C drive_do not delete\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.2.1
npm ERR! npm  v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! rest-server@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rest-server@0.0.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the rest-server package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs rest-server
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls rest-server
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\APOORVA\Desktop\Coursera\rest-server\npm-debug.log

我的package.json文件

    {
  "name": "rest-server",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.15.1",
    "cookie-parser": "~1.4.3",
    "debug": "~2.2.0",
    "express": "~4.13.4",
    "jade": "~1.11.0",
    "mongoose": "^4.5.9",
    "mongoose-currency": "^0.2.0",
    "morgan": "~1.7.0",
    "serve-favicon": "~2.3.0"
  }
}

app.js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var mongoose = require('mongoose');

var url = 'mongodb://localhost:27017/conFusion';
mongoose.connect(url);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
    // we're connected!
    console.log("Connected correctly to server");
});

var routes = require('./routes/index');
var users = require('./routes/users');
var dishRouter = require('./routes/dishRouter');
var promoRouter = require('./routes/promoRouter');
var leaderRouter = require('./routes/leaderRouter');

var app = express();

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

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/',routes);
app.use('/users', users);
app.use('/dishes',dishRouter);
app.use('/promotions',promoRouter);
app.use('/leadership',leaderRouter);

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

// error handlers

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

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});


module.exports = app;

0 个答案:

没有答案