Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Node.js: listen EACCES permission denied on port 80

EACCES on listen means the process cannot bind that port. Learn the privileged port rule, capability grants, reverse proxies, and the EADDRINUSE twin.

~5 min readNode.js
#nodejs#eacces#networking#permissions
Bold white headline reading PORT DENIED with a Node server crate blocked at a locked cyan port gate on the right.

Introduction & Quick Summary

Node exits at startup because the operating system refused the bind:

code
node:events:496 throw er; // Unhandled 'error' event ^ Error: listen EACCES: permission denied 0.0.0.0:80 at Server.setupListenHandle [as _listen2] (node:net:1908:16) at listenInCluster (node:net:1965:12) at Server.listen (node:net:2074:7) errno: -13, code: 'EACCES', syscall: 'listen', address: '0.0.0.0', port: 80

EACCES from listen means the kernel refused the socket bind, and the cause is almost always the port number. Ports below 1024 are privileged on Linux and macOS: only a process with CAP_NET_BIND_SERVICE or an effective user ID of 0 may bind them. The error names the address and port that failed, so the first check is whether the port is below 1024 and who the process runs as.

Where it appears:

  • app.listen(80) or app.listen(443) started as a normal user.
  • A container image switched to USER node but kept EXPOSE 80.
  • A CI job or systemd unit that runs the app as a service account.
  • A port that is not privileged but is blocked by SELinux, or is already held by another process.
  • macOS, where port 5000 and 7000 are taken by AirPlay Receiver.

Quick answer: do not run Node as root for this. Bind a high port and put nginx, Caddy, or the platform's proxy in front, or grant only the bind capability to the binary.

Core Mechanics, Signatures & Reproducible Setup

server.listen() calls bind(2). The kernel checks the port against the privileged range and the caller's credentials. On Linux, net.ipv4.ip_unprivileged_port_start (default 1024) defines the boundary; CAP_NET_BIND_SERVICE is the capability that grants an exception without root.

js
// repro.mjs -- run as a normal user: node repro.mjs import http from "node:http"; const server = http.createServer((req, res) => res.end("ok")); server.on("error", (err) => { console.error("listen failed", { code: err.code, errno: err.errno, syscall: err.syscall, address: err.address, port: err.port, }); process.exit(1); }); server.listen(80, "0.0.0.0", () => { console.log("listening", server.address()); });
bash
node repro.mjs # listen failed { code: 'EACCES', errno: -13, syscall: 'listen', address: '0.0.0.0', port: 80 }

The attached error object is what makes this class of bug fast to diagnose. Without an error handler, Node throws the raw event and exits with a stack that names node:net internals rather than your code.

Errors that look alike and mean different things:

CodeMeaningTypical cause
EACCESpermission denied on bindprivileged port, SELinux policy, capabilities dropped
EADDRINUSEaddress already in useanother process holds the port
EADDRNOTAVAILaddress not availablebinding an IP that is not on this host
EPERMoperation not permittedcontainer dropped the capability explicitly
ENOTFOUNDname not resolvedwrong host value passed to listen

Reproducible setup for the fixes below:

bash
node --version id -u # 0 means root; anything else needs a workaround ss -ltnp | grep ':80 ' # is something already listening? getcap "$(command -v node)" # empty output means no bind capability

Key Comparison Table

FixCommand or configTrade-off
Bind a high portapp.listen(3000)needs a proxy to answer on 80 and 443
Grant the capability to the binarysetcap 'cap_net_bind_service=+ep' $(command -v node)applies to every script that binary runs
Grant it to one copycopy node to /opt/app/node and setcap that filean extra binary to keep updated
Lower the privileged rangesysctl net.ipv4.ip_unprivileged_port_start=80host-wide change, weaker isolation
Run as rootUSER root in the imageevery request now runs with root rights
Map a container portdocker run -p 80:3000the container itself stays unprivileged

Which one fits:

EnvironmentRecommendedWhy
Single VM with nginxhigh port plus proxyone place terminates TLS, restarts are independent
Container on KubernetescontainerPort: 3000, Service port 80the kubelet proxies, the pod stays non-root
Docker Compose on a hostports: "80:3000"the daemon binds the low port, not the app
Bare systemd serviceAmbientCapabilities=CAP_NET_BIND_SERVICEper-unit grant, no root user
Local developmenthigh portno privileges needed, no proxy to configure

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Confirm it is the port before changing permissions

Read the port from the error object, not from the code you think ran. Environment files and process managers override values silently.

js
const port = Number(process.env.PORT ?? 3000); server.listen(port, "0.0.0.0");
bash
PORT=80 node server.mjs # reproduces the failure in one line ss -ltnp | grep ':80 ' # EADDRINUSE would show a process here

If ss shows nothing listening and id -u is not 0, it is the privileged-port rule.

2. Grant the capability in a container image

setcap must run after the binary is copied and before the user changes, and it needs the capability tools in the build stage.

dockerfile
FROM node:22-bookworm-slim RUN apt-get update \ && apt-get install -y --no-install-recommends libcap2-bin \ && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY package*.json ./ RUN npm ci --omit=dev COPY . . RUN setcap 'cap_net_bind_service=+ep' "$(command -v node)" \ && chown -R node:node /app USER node EXPOSE 80 CMD ["node", "server.mjs"]

Two failure modes remain: a base image rebuild replaces the binary and drops the capability, and a host with no_new_privileges refuses the file capability. Prefer -p 80:3000 for Compose and let the daemon bind the port.

3. systemd without root

A unit can grant the capability to just that service and keep the process unprivileged.

ini
# /etc/systemd/system/api.service [Service] User=api WorkingDirectory=/srv/api ExecStart=/usr/bin/node /srv/api/server.mjs Environment=PORT=80 AmbientCapabilities=CAP_NET_BIND_SERVICE CapabilityBoundingSet=CAP_NET_BIND_SERVICE NoNewPrivileges=true
bash
sudo systemctl daemon-reload sudo systemctl restart api journalctl -u api -n 20 --no-pager

AmbientCapabilities survives exec, which is why it works here and a plain setcap on a shell script does not. The service still runs as api, so a bug in the app cannot rewrite system files.

4. Put a proxy in front and stay on a high port

For anything serving real traffic, the proxy is the better answer: it terminates TLS, handles HTTP/2, and can restart the app without dropping the listening socket.

caddyfile
# Caddyfile example.com { reverse_proxy 127.0.0.1:3000 }
nginx
# nginx equivalent server { listen 80; server_name example.com; location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }

Then verify from outside with curl: curl -I http://127.0.0.1:3000/health first, then the public host. If the proxy is up and the app is not, you get a 502, which the status codes reference explains at a glance.

5. Handle macOS and port 5000

On macOS, EACCES on ports 5000 and 7000 usually means AirPlay Receiver holds them, because those ports are not privileged.

bash
# macOS: find the listener lsof -nP -iTCP:5000 -sTCP:LISTEN # turn off AirPlay Receiver in System Settings > General > AirDrop & Handoff

Ports in the 4900 to 5000 range also collide with other Apple services and with other developers' projects. Pick a fixed port above 8000 for development and set it in one place, such as PORT in an env file loaded by the start script.

Common Compilation/Runtime Mistakes & Version Gotchas

Running the process as root to make the error go away. It works and it is the worst of the options: a remote-code-execution bug now has root, and the container's own USER protection is gone. The container port mapping exists precisely so this is unnecessary.

Setting the capability on the wrong binary. In images built with nvm, on systems with multiple Node installations, or with npm start calling a shim, $(command -v node) in the build stage may not be the binary that runs. Use readlink -f "$(command -v node)" and check getcap on the final path.

Confusing EACCES with EADDRINUSE. Both arrive as listen errors. ss -ltnp, lsof -i, or a second bind attempt tells them apart; changing permissions never fixes a port that another process holds.

Binding a specific address that does not exist. app.listen(80, "192.168.1.10") fails with EADDRNOTAVAIL or EACCES depending on the platform when that IP is not on the interface. Bind 0.0.0.0 or :: and let the proxy decide the interface.

IPv6 versus IPv4. listen(3000) without a host binds :: on most systems and accepts IPv4-mapped connections; listen(3000, "127.0.0.1") refuses them. A proxy pointing at localhost may resolve to ::1 and fail while the app is running, which looks like a crash but is a connection refused.

Version and platform notes. Node 18 and later report the same errno values but print the stack differently; the code, syscall, address, and port fields are stable and are what you should log. In Docker Desktop for macOS, port 80 on the host may already be bound by the desktop proxy, so the daemon replies EADDRINUSE before your code ever runs. On hosts with SELinux enforcing, http_port_t restricts which ports a service may bind, and semanage port -a -t http_port_t -p tcp 8080 is the supported fix.

Check the environment before the code. When the failure starts after a deployment, compare the deployed PORT with the environment file you expect and confirm the listening state with curl before touching permissions.

Reference material: net.Server.listen and Common system errors.

Official references

primary documentation

The Node.js documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Node.js work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Node.js guides

More in Node.js

All Node.js guides

The guides filed next to this one in Node.js, in library order.