Node.js · Ports

EADDRINUSE: address already in use

Your bot tried to listen on a port another process already has. Only one process can hold a port at a time, so the second one stops before it starts.

← All errors

What you are seeing

Node.js

Error: listen EADDRINUSE: address already in use :::3000

Why a bot listens at all

A Discord bot on its own never listens on a port, so this error means your bot also runs a small web server: a keep-alive page, a dashboard, a webhook receiver, or an Express server for an OAuth callback. If your bot has no server code at all, something else on the machine is using that port — or a second copy of your bot is running, and the first copy already holds it.

Find who has the port

The number at the end of the error is the port. On Linux, ss shows what is listening on it; on macOS, lsof does; on Windows, netstat with the process ID. If the process is your own bot, stop it before starting a new copy. If it is something else, give your bot a different port — read it from an environment variable so the code does not need changing each time.

Linux

# Which process is listening on port 3000?
ss -ltnp | grep 3000

macOS

# Which process is listening on port 3000?
lsof -i :3000

Node.js

const port = process.env.PORT || 3000;

server.listen(port, () => console.log(`Listening on ${port}`));

server.on('error', (error) => {
    if (error.code === 'EADDRINUSE') {
        console.error(`Port ${port} is already in use — is another copy of the bot running?`);
        process.exit(1);
    }
    throw error;
});

The second copy

The most common cause is the same one behind the Telegram 409 and the Discord 10062 pages: the bot is still running on your own computer after you started it on a server, or a deploy started a new copy without stopping the old one. Stop every copy you know of, then start exactly one.

FAQ

Questions

It works on my computer and not on the server.

The port is taken on the server by another process, or the server is running your bot twice. Find what is listening there before changing your code.

Can two bots share one port?

No. Each process needs its own port, so give each its own PORT value.

What about EACCES?

A different error: the port is below 1024 and needs administrator privileges to bind. Use a port above 1024 instead.

Read next