http - Node.js EACCES error when listening on most ports

ID : 10368

viewed : 13

Tags : httpnode.jspermission-deniedhttp

Top 5 Answer for http - Node.js EACCES error when listening on most ports

vote vote

97

Running on your workstation

As a general rule, processes running without root privileges cannot bind to ports below 1024.

So try a higher port, or run with elevated privileges via sudo. You can downgrade privileges after you have bound to the low port using process.setgid and process.setuid.

Running on heroku

When running your apps on heroku you have to use the port as specified in the PORT environment variable.

See http://devcenter.heroku.com/articles/node-js

const server = require('http').createServer(); const port = process.env.PORT || 3000;  server.listen(port, () => console.log(`Listening on ${port}`)); 
vote vote

89

Non-privileged user (not root) can't open a listening socket on ports below 1024.

vote vote

79

Check this reference link:

Give Safe User Permission To Use Port 80

Remember, we do NOT want to run your applications as the root user, but there is a hitch: your safe user does not have permission to use the default HTTP port (80). You goal is to be able to publish a website that visitors can use by navigating to an easy to use URL like http://ip:port/

Unfortunately, unless you sign on as root, you’ll normally have to use a URL like http://ip:port - where port number > 1024.

A lot of people get stuck here, but the solution is easy. There a few options but this is the one I like. Type the following commands:

sudo apt-get install libcap2-bin sudo setcap cap_net_bind_service=+ep `readlink -f \`which node\`` 

Now, when you tell a Node application that you want it to run on port 80, it will not complain.

vote vote

64

#Windows

Another one reason - maybe your port has been excluded by some reasons.

So, try open CMD (command line) under admin rights and run :

  1. net stop winnat
  2. net start winnat

In my case it was enough.

Solution found here : https://medium.com/@Bartleby/ports-are-not-available-listen-tcp-0-0-0-0-3000-165892441b9d

vote vote

55

On Windows System, restarting the service "Host Network Service", resolved the issue.

Top 3 video Explaining http - Node.js EACCES error when listening on most ports

Related QUESTION?