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.

Introduction & Quick Summary
Node exits at startup because the operating system refused the bind:
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: 80EACCES 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)orapp.listen(443)started as a normal user.- A container image switched to
USER nodebut keptEXPOSE 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.
// 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());
});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:
| Code | Meaning | Typical cause |
|---|---|---|
EACCES | permission denied on bind | privileged port, SELinux policy, capabilities dropped |
EADDRINUSE | address already in use | another process holds the port |
EADDRNOTAVAIL | address not available | binding an IP that is not on this host |
EPERM | operation not permitted | container dropped the capability explicitly |
ENOTFOUND | name not resolved | wrong host value passed to listen |
Reproducible setup for the fixes below:
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 capabilityKey Comparison Table
| Fix | Command or config | Trade-off |
|---|---|---|
| Bind a high port | app.listen(3000) | needs a proxy to answer on 80 and 443 |
| Grant the capability to the binary | setcap 'cap_net_bind_service=+ep' $(command -v node) | applies to every script that binary runs |
| Grant it to one copy | copy node to /opt/app/node and setcap that file | an extra binary to keep updated |
| Lower the privileged range | sysctl net.ipv4.ip_unprivileged_port_start=80 | host-wide change, weaker isolation |
| Run as root | USER root in the image | every request now runs with root rights |
| Map a container port | docker run -p 80:3000 | the container itself stays unprivileged |
Which one fits:
| Environment | Recommended | Why |
|---|---|---|
| Single VM with nginx | high port plus proxy | one place terminates TLS, restarts are independent |
| Container on Kubernetes | containerPort: 3000, Service port 80 | the kubelet proxies, the pod stays non-root |
| Docker Compose on a host | ports: "80:3000" | the daemon binds the low port, not the app |
| Bare systemd service | AmbientCapabilities=CAP_NET_BIND_SERVICE | per-unit grant, no root user |
| Local development | high port | no 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.
const port = Number(process.env.PORT ?? 3000);
server.listen(port, "0.0.0.0");PORT=80 node server.mjs # reproduces the failure in one line
ss -ltnp | grep ':80 ' # EADDRINUSE would show a process hereIf 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.
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.
# /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=truesudo systemctl daemon-reload
sudo systemctl restart api
journalctl -u api -n 20 --no-pagerAmbientCapabilities 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
example.com {
reverse_proxy 127.0.0.1:3000
}# 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.
# macOS: find the listener
lsof -nP -iTCP:5000 -sTCP:LISTEN
# turn off AirPlay Receiver in System Settings > General > AirDrop & HandoffPorts 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 documentationThe Node.js documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Node.js work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Node.js guides
All Node.js guidesNode.js: ERR_DLOPEN_FAILED invalid ELF header
Invalid ELF header means a native addon was built for another OS or architecture. Rebuild it inside the target image instead of copying node_modules.
Node.js ERR_INVALID_ARG_TYPE: the argument must be of type
ERR_INVALID_ARG_TYPE is Node's validator naming a wrong argument. Read the quoted argument, validate at the boundary and default env values.
ERR_MODULE_NOT_FOUND: Cannot find module imported from an ESM file
ESM resolves specifiers literally: extensions are required, directories do not resolve to index files, and exports maps block deep imports.
Node.js 26 upgrade: rmdir, native addons and removed flags
Three breaks stop a deploy: rmdir with recursive throws, the transform-types flag is gone, and the module ABI moved to 147.
More in Node.js
All Node.js guidesThe guides filed next to this one in Node.js, in library order.