0

I'm trying to setup Socket.io with Express, and I'm using the exact code from the Socket.io documentation, which is this:

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

server.listen(80);

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

io.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

The error I'm getting when I'm running app.js is this:

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EACCES 0.0.0.0:80
    at Object.exports._errnoException (util.js:849:11)
    at exports._exceptionWithHostPort (util.js:872:20)
    at Server._listen2 (net.js:1218:19)
    at listen (net.js:1267:10)
    at Server.listen (net.js:1363:5)
    at Object.<anonymous> (/Users/leondewit/PhpstormProjects/websocket_test/app.js:5:8)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

Does anyone know what might be wrong?

Leon
  • 1,999
  • 22
  • 38

1 Answers1

0

You cannot bind to ports lower than 1024 in a system without sudo or admin permissions.

These ports are called privileged ports, here is a link to a wikipedia article with some ports and their associated services

Ideally when you are developing, for ease of use, you should uses a number generally higher than 3000 to be safe.

Sgnl
  • 1,808
  • 22
  • 30