简体   繁体   English

Node.js终端给出错误:听EADDRINUSE ::: 8080

[英]Node.js terminal giving Error: listen EADDRINUSE :::8080

I am creating an app in Node.js when I am running it in the terminal with nodemon app.js command I am getting this error 当我在终端中使用nodemon app.js命令运行它时,我在Node.js中创建了一个应用程序我收到此错误

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...

My app.js 我的app.js.

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);

When I login then instead of showing message Logged In it gives Internal Server Error Please help me fix the problem. 当我登录然后而不是显示消息Logged In它给出Internal Server Error请帮助我解决问题。

port 8080 is the defaul http port for Tomcat Web Server. 端口8080是Tomcat Web Server的默认http端口。 Is there a chance that you have Tomcat running as well? 您是否有机会运行Tomcat? Do you get the same error if you change your port to something other than 8080? 如果将端口更改为8080以外的其他端口,是否会出现相同的错误?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM