4

I've searched on other questions in here about this error but I couldn't find a solution.

Yesterday I deployed a Node + Express + Socket.IO website to Azure, and it doesn't work. I get the error

Application has thrown an uncaught exception and is terminated: Error: listen EACCES 0.0.0.0:80

in this code:

// more code ...

var app = express();

var server = require('http').Server(app);

var io = require('socket.io')(server);

// right here
server.listen(portNumber, function () {
  console.log('Server listening at port %d', portNumber);
});

// more code ...

It looks as if another process is already listening on this port.. maybe IIS Server? I'm not sure.

Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130

4 Answers4

7

You should set portNumber as follow :

var portNumber = process.env.port || process.env.PORT || 1337

Azure passes a port in the variable process.env.PORT and you have to use it because it is not really a port but a pipe like \\\\.\\pipe\\2f95e604-fc02-4365-acfc-010a26242d02.

ylliac
  • 173
  • 3
  • 9
0

This error means that you have no privileges to listen on that port. If something else was already listening on that port you should get an error like:

Error: listen EADDRINUSE 0.0.0.0:80

You need to run as root to listen on ports below 1024.

Or you can run a reverse proxy that proxies requests from port 80 to some higher port that your app listens on.

rsp
  • 107,747
  • 29
  • 201
  • 177
0

Try running the application as a root user.

sudo node app.js
0

I don't know Azure , but i know this: Something is trying to listen to port 80, and this requires admin access (windows)/ sudo permission (ubuntu). first of all, change your settings, port 80 is the main port for the computer to listen to anything from the outer world, don't change that. Giving your app admin access/sudo permission can bring down the whole system if an error throws in your application, don't give these privileges to the app. If you MUST listen to port 80, listen to another port, and proxy from port 80 to that port

Ahmad Mayo
  • 743
  • 1
  • 6
  • 12