DEV Community

Médéric Burlet for Pixium Digital

Posted on

3 1

Listen on port 80 for node in linux

Node Permission Denied

Today I came across a node error when trying to run a simple express server on a amazon ec2.

Error: listen EACCES: permission denied 0.0.0.0:80

After some commands and research I realized that Linux architechture by default only lets ports lower than 1024 be listened by root.

This means that for running applications such as node which, should not be ran as root, we need to create a port redirect.

Using iptables to fix it

iptables is a user-space utility program that allows a system administrator to configure the tables provided by the Linux kernel firewall.

We will create a redirect of port 80 to 8080 in our scenario.

sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

To check if the route has been added successfully you can execute the following command:

sudo iptables --table nat --list

You should see something like this:

REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay