-1

I have this error when i try run my script.

{ [Error: listen EADDRINUSE :::8000]
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '::',
  port: 8000 }
Error: listen EADDRINUSE :::8000
    at Object.exports._errnoException (util.js:890:11)
    at exports._exceptionWithHostPort (util.js:913:20)
    at Server._listen2 (net.js:1234:14)
    at listen (net.js:1270:10)
    at Server.listen (net.js:1366:5)
    at Server.listen.Server.attach (/usr/lib/node_modules/socket.io/lib/index.js:216:9)
    at Timeout._onTimeout (/var/www/html/Bot/site.js:618:29)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)

Script.js around ~605 Line

function load() {
    query('SET NAMES utf8');
    query('SELECT `id` FROM `rolls` ORDER BY `id` DESC LIMIT 1', function(err, row) {
        if((err) || (!row.length)) {
            logger.error('Cant get number from the last game');
            logger.debug(err);
            process.exit(0);
            return;
        }
        currentRollid = row[0].id;
        logger.trace('Roll '+currentRollid);
    });
    loadHistory();
    setTimeout(function() { io.listen(8080); }, 3000);
}

618 line is

setTimeout(function() { io.listen(8080); }, 3000);

How i can fix this ? I try change io.listen Port but its still dont work.

1 Answers1

0

Firstly, you should know that the EADDRINUSE error, gets thrown whenever the port that you're trying to listen on, is already in-use.

To fix this problem, you're going to need to free-up the port that your application is trying to listen on (if you're using Linux, perhaps you'll find this StackOverflow thread to be of use).

When creating servers in NodeJS, it's generally a good idea to listen for [process] exit events, so you can close your server, thus freeing up the port that it's listening on.

Here's some great documentation that provides information about different events that can be fired before a NodeJS process is terminated:

Going based on the snippets that you provided, I'm making the assumption that you're using SocketIO.

This StackOverflow answer gives a great example about how to close a SocketIO server.

Community
  • 1
  • 1
Brynden Bielefeld
  • 30,727
  • 1
  • 12
  • 19