首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Node.js终端出现错误: listen EADDRINUSE :8080

问Node.js终端出现错误: listen EADDRINUSE :8080
EN

Stack Overflow用户
提问于 2017-02-14 21:26:19
回答 1查看 1.2K关注 0票数 1

当我使用nodemon app.js命令在终端中运行应用程序时,我在Node.js中创建了一个应用程序,我收到以下错误

代码语言:javascript
复制
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::8080
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at Server._listen2 (net.js:1259:14)
    at listen (net.js:1295:10)
    at Server.listen (net.js:1391:5)
    at EventEmitter.listen (E:\xampp\htdocs\sites\nodeapp\node_modules\express\lib\application.js:617:24)
    at Object.<anonymous> (E:\xampp\htdocs\sites\nodeapp\app.js:79:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
[nodemon] app crashed - waiting for file changes before starting...

我的app.js

代码语言:javascript
复制
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var morgan = require('morgan');
var jwt = require('jsonwebtoken');
var config = require('./config');
var user = require('./modal/user');
//var alte = require('admin-lte');

// set up view engine
app.set('view engine', 'ejs');

// set up static files
app.use(express.static('./'));

// configuration
var port = process.env.PORT || 8080; // used to create, sign, and verify tokens
mongoose.connect(config.database); // connect to database
app.set('superSecret', config.secret); // secret variable

// use body parser so we can get info from POST and/or URL parameters
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// use morgan to log requests to the console
app.use(morgan('dev'));

// routes
// basic route to home/landing
app.get('/', function(req, res) {
    res.render('index');
});

// route to create user
app.get('/setup', function(req, res){
  //create user
  var nick = new user({
    username: 'test',
    password: 'test',
    admin: true
  });

  //save user
  nick.save(function(err){
    if(err) throw err;
    console.log('User saved successfully!');
    res.json({success: true});
  });
});

// route to get data from form
app.post('/authenticate', function(req, res){
    //find user
    user.findOne({username: req.body.username}, function(err, myuser){
      if(err) throw err;
      if(!myuser){
        //if user not found throw error
        res.json({success: false, message: 'Authentication failed. User not found.'});
      }else{
        // if user found, check if password matches
        if(myuser.password != req.body.password){
          //if password does not match throw error
          res.json({success: false, message: 'Authentication failed. Password mismatch.'});
        }else{
          //if password matches create token
          var token = jwt.sign(myuser, app.get('superSecret'), {expiresIn: 86400});
          //res.render('dashboard');
          res.send('Logged In')
        }
      }
    });
});

// API ROUTES -------------------
// we'll get to these in a second

// start the server
app.listen(port);
console.log('Listening to port ' + port);

当我登录时,它会显示Internal Server Error,而不是显示消息Logged In,请帮助我解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2017-02-14 21:31:25

端口8080是Tomcat Web Server的默认http端口。有没有可能让Tomcat也在运行?如果将端口更改为8080以外的其他端口,是否会出现相同的错误?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42227366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档