Node.js Unhandled event "error" when using http.createServer (). listen () on Ubuntu 12.04

Salam (means Hello) :)

I developed a node.js script on my machine with seven windows and it works fine. but when I run it on my Ubuntu 12.04, the following error appears and stops my application:

throw er; // Unhandled 'error' event ^ Error: listen EACCES at errnoException (net.js:901:11) at Server._listen2 (net.js:1020:19) at listen (net.js:1061:10) at Server.listen (net.js:1127:5) at Object.start (/httpServer/httpServer.js:9:34) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) 

and the point that caused the error is .listen(80) on this line:

 http.createServer(onRequest).listen(80); ^ 

I also tried some other port numbers (e.g. 100, 300, 500, ...) instead of 80 , and the error was the same.

+6
source share
6 answers

On Ubuntu, you cannot listen on ports <1024 without root privileges. Try running node under sudo.

 sudo node app.js 
+13
source

Apache is probably running on port 80, so it conflicts.

Use a different port (not between 0-1023) or disable apache.

Greetings

+6
source

You probably have something else running on port 80, so it conflicts.

Read here to find out what port 80 is using and stop it http://www.cyberciti.biz/faq/find-linux-what-running-on-port-80-command/

  • This usually means that another server, such as apache, is enabled. so stop it.

    sudo service apache2 stop

  • or you already have npm start already on another terminal

  • or skype works. in this case, go to settings and change the port. logout n login

    Go to Tools β†’ Options β†’ Advanced β†’ Connections and uncheck "Use port 80 and 443 as an alternative." src

  • or use another port

    http-server -a localhost -p 8000

+1
source

I suggest installing the latest node packages, possibly directly from the Node.js server, maybe compiling it.

Try installing a port that is not reserved for any service, such as 3700.

Maybe he was caring to see some other piece of code.

0
source

It can also be caused if you have something else already listening on this port - you can try changing the port from a typical default of 80 to something larger than 10014 and see if that helps!

0
source

I was able to fix the error by explicitly specifying an β€œIP address” along with the port while listening to the server.

0
source

Source: https://habr.com/ru/post/957300/


All Articles