Nasser Torabzade
Nasser Torabzade

Reputation: 6710

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

Salam (means Hello) :)

I've developed a node.js script on my windows seven machine and it's working fine. but when I run it on my Ubuntu 12.04, the following error shows up and halts my app:

    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 error is .listen(80) in this line:

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

I've also tried some other port numbers (like 100, 300, 500,...) instead of 80 and the error was still the same.

Upvotes: 6

Views: 4639

Answers (6)

aWebDeveloper
aWebDeveloper

Reputation: 38352

You probably have something else running on port 80, so it's conflicting.

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

  1. Usually it means another server like apache is enabled. so stop it.

    sudo service apache2 stop

  2. or You have npm start already running in another terminal

  3. or skype is running. in which case go to settings and change it's port. logout n login

    Go to Tools -> Options -> Advanced -> Connections and uncheck the box "use port 80 and 443 as alternative".src

  4. or use another port

    http-server -a localhost -p 8000

Upvotes: 1

Dharshni
Dharshni

Reputation: 191

I was able to rectify the error by explicitely mentionining the "IP address" along with the port when listening to the server.

Upvotes: 0

Cameron
Cameron

Reputation: 1524

This can also be caused if you have something else already listening on that port - you can try changing the port from the typical default 80 to something more like 10014 and see if that helps!

Upvotes: 0

BadCanyon
BadCanyon

Reputation: 3133

On Ubuntu you can't listen on ports < 1024 without root privileges. Try running node under sudo.

sudo node app.js

Upvotes: 13

Luc Morin
Luc Morin

Reputation: 5380

You probably have apache running on port 80, so it's conflicting.

Use another port (NOT within 0-1023), or disable apache.

Cheers

Upvotes: 7

Edoardoo
Edoardoo

Reputation: 2909

I suggest to install the latest node packets, maybe directly from Node.js server, maybe compiling it.

Try to set a port which is not reserved to any service, like 3700.

Could be heplful to see some other fragment of code, though.

Upvotes: 0

Related Questions