EADDRINUSE :::3000 error - how do i fix this?

June 29, 2017 334 views
Node.js Nginx Apache Debian

If I try to do "node <script" i am presented with this error log:
Error: listen EADDRINUSE :::3000
at Object.exports.errnoException (util.js:1026:11)
at exports.
exceptionWithHostPort (util.js:1049:20)
at Server.setupListenHandle [as listen2] (net.js:1305:14)
at listenInCluster (net.js:1353:12)
at Server.listen (net.js:1453:7)
at Server.listen.Server.attach (/home/Bot/node
at Timeout._onTimeout (/home/Bot/site.js:1005:29)
at ontimeout (timers.js:488:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:283:5)
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 3000 }

anyone know how to fix?

4 Answers

Hi @k0ala

Something is already running and listening on port 3000 of the IPv6 interface.
Run this command to list the services running:

sudo lsof -iTCP -sTCP:LISTEN -P
    rpcbind  1690        root    8u  IPv4   4975      0t0  TCP *:111 (LISTEN)
    rpcbind  1690        root   11u  IPv6   4982      0t0  TCP *:111 (LISTEN)
    mysqld   2541       mysql   10u  IPv4   5726      0t0  TCP localhost:3306 (LISTEN)
    nginx    2563        root    6u  IPv4   5625      0t0  TCP *:80 (LISTEN)
    sshd     2584        root    3u  IPv4   5656      0t0  TCP *:22 (LISTEN)
    sshd     2584        root    4u  IPv6   5658      0t0  TCP *:22 (LISTEN)
    exim4    3010 Debian-exim    3u  IPv4   6240      0t0  TCP localhost:25 (LISTEN)
    exim4    3010 Debian-exim    4u  IPv6   6241      0t0  TCP ip6-localhost:25 (LISTEN)
    apache2  3581        root    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2  3601    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2  3602    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2  3603    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2  3604    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2  3605    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2  3624    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    nginx    3778    www-data    6u  IPv4   5625      0t0  TCP *:80 (LISTEN)
    nginx    3779    www-data    6u  IPv4   5625      0t0  TCP *:80 (LISTEN)
    nginx    3780    www-data    6u  IPv4   5625      0t0  TCP *:80 (LISTEN)
    nginx    3781    www-data    6u  IPv4   5625      0t0  TCP *:80 (LISTEN)
    apache2  3908    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2  3975    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2  4027    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)
    apache2 10186    www-data    4u  IPv6  12058      0t0  TCP *:8080 (LISTEN)


Okay, those configurations doesn't seem to do anything and it doesn't match the ports the services are listening on.

So you're only interested in running a Node.js application ?

May I recommend that you start over by reinstalling the server, following this tutorial:

Otherwise you could start a droplet using the One-Click App, which would give you a pre-installed Node.js with Nginx (I think it comes with, but might be Apache).

Node.js is an open source JavaScript runtime environment for easily building server-side and networking applications. Node.js applications can be run at the command line but this guide focuses on running them as a service using PM2, so that they will automatically restart on reboot or failure, and can safely be used in a production environment.
  • reinstalled and it does nothing, even if i run it with the pm2 thing
    I really do not want to start a new droplet...

    • @k0ala
      You cannot use PM2 until the Node application is running.
      Is it a home made application you're trying to run or an application you've downloaded from somewhere, if yes, where?

    • And you can reinstall with a One-Click on the current droplet, if you don't want to spin up another. Go to the control panel, click the droplet, click Destroy in the menu on the left, search for "NodeJS 6.11", and click Rebuild.

      • damn it... wish you told me that it would reset all the files...... I didn't have a backup... partly my fault though i wasnt paying attention and just did what you told me to

        • @k0ala

          I guess the "Destroy" was telling enough - and since you stated that you reinstalled just before that, then I guessed you didn't have any data.

          • ok well apparently i saved the files and i got them back but i had to go through a bunch of reinstalls and it still doesn't work because it gives me the eaddrinuse... I looked it up some more and people are telling me to change the port, but i don't understand how to change it. here's the error log

            [Error: listen EADDRINUSE] code:                    'EADDRINUSE', errno: 'EADDRINUSE', syscall: 'listen' }
            Error: listen EADDRINUSE
                at exports._errnoException (util.js:746:11)
                at Server._listen2 (net.js:1158:14)
                at listen (net.js:1184:10)
                at Server.listen (net.js:1269:5)
                at Server.listen.Server.attach (/home/Bot/node_modules/socket.io/lib/index.j                   s:216:9)
                at null._onTimeout (/home/Bot/site.js:1005:29)
                at Timer.listOnTimeout (timers.js:119:15)

            I tried changing the number at " at Server.listen.Server.attach (/home/Bot/node_modules/socket.io/lib/index.js:216:9)" as it describes here which is a port number, but that doesn't do anything either. So how would i go about changing the port??


That's good you have backup - very important.

You shouldn't need to install anything - except if you use non-standard Node modules.

Is it your own code or is it a project you have downloaded?
If it's your own code, then you need to post it in www.pastebin.com so we can have a look at the configuration, because it seems like it's not configured correctly.
If it's a project, which and from where have you downloaded it?

  • i think this may be the problem, i have no idea though: https://gyazo.com/218fe6888283989be3438db10bc8cf42

  • is there anyway i could contact you outside of this place to make things quicker?

    • @k0ala I charge $200/hour in my normal day job, so don't think you want that :)

      But you keep not replying to my questions. Is it your own code or not?

      You need to find your location / { block in /etc/nginx/sites-enabled/ and add the following line to that block:

      add_header Access-Control-Allow-Origin "*";
      • well, i fixed the issue and my site works now lol. I changed the port to 8080 but the only thing is the database isn't working and i think that's an issue with my code. thanks for all the help

Have another answer? Share your knowledge.