Node.js cannot listen: EACCES permission denied on a port
Error: listen EACCES: permission denied 0.0.0.0:80Short answer
On Linux, ports below 1024 are privileged. A normal user cannot bind to them, so listen fails with EACCES. Keep the app on a high port behind a reverse proxy, or give the process only the CAP_NET_BIND_SERVICE capability. Do not run the whole app as root.
Fix it fast
1Find out which cause you have
Read the address in the error. A port under 1024 points to the first cause; a file path points to the second.
node server.js 2>&1 | grep EACCES id -u2Match what you see, then jump to its fix
- 1
listen EACCES: permission denied 0.0.0.0:80 or :443Port below 1024 without the right to bind itFix - 2
You started node from a plain shell as a normal user and no capability is setThe capability must be on the process, not just wantedFix - 3
listen EACCES: permission denied /run/my-app.sock (a path, not a port)A Unix socket path the user cannot useFix
- 1
What does the error look like?
Error: listen EACCES: permission denied 0.0.0.0:80code: 'EACCES', syscall: 'listen'
Cause 1 of 3
Port below 1024 without the right to bind it
1Check
Linux calls ports below 1024 privileged. Binding to one needs the CAP_NET_BIND_SERVICE capability, which a normal user does not have; EACCES is the documented error for it.
id -u
grep -n "listen" server.js2Fix
Best: run the app on a high port such as 3000 and let nginx or another proxy own 80 and 443. If you must bind low ports directly, grant the capability to the service instead of using root.
# systemd unit
[Service]
User=app
AmbientCapabilities=CAP_NET_BIND_SERVICE3Verify
Restart the service and request the port.
sudo systemctl daemon-reload && sudo systemctl restart my-app
curl -I http://127.0.0.1:80Confirmed by man7.org
Cause 2 of 3
The capability must be on the process, not just wanted
1Check
CAP_NET_BIND_SERVICE is what allows binding to ports below 1024. Without it on the process or the binary, the kernel refuses. Check what the Node.js binary has.
getcap $(readlink -f $(which node))2Fix
For a quick local test, add the capability to the Node.js binary. This applies to every script run with that binary, so avoid it on shared servers.
sudo setcap cap_net_bind_service=+ep $(readlink -f $(which node))3Verify
Start the app on the low port as the normal user.
node server.jsConfirmed by man7.org
Cause 3 of 3
A Unix socket path the user cannot use
1Check
For an IPC path, the server owner and permissions decide who can connect. The Node.js net docs note that a server started as root may leave a path other users cannot reach.
ls -l /run/my-app.sock2Fix
Start the server as the same user that should own it, or set readableAll and writableAll when listening, so all users can reach it.
server.listen({ path: '/run/my-app.sock', readableAll: true, writableAll: true });3Verify
A client can connect through the socket.
curl --unix-socket /run/my-app.sock http://localhost/Confirmed by nodejs.org
How do I stop it coming back?
- Terminate TLS and own ports 80 and 443 in a reverse proxy; keep Node.js on a high port.
- Never run the full Node.js app as root just to bind a port.
- Put capability settings in the unit file so they survive redeploys.
- Print the port from config at start-up so a wrong value is obvious.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Node.js cannot start because the port is already taken
Error: listen EADDRINUSE: address already in use 127.0.0.1:8080
EADDRINUSE means another socket already listens on that port, so Node's listen() was refused.
4 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
firebase deploy stops because the predeploy lint step failed
Error: There was an error deploying functions
The predeploy hook in firebase.json runs npm run lint before every deploy, and a failing hook cancels the deploy.
3 causes, each with a fix