Node.js websocket error "Error: listen EADDRNOTAVAIL Error: listen EADDRNOTAVAIL"

Port 22 is reserved for ssh and on the list of well known ports, please check http://en.wikipedia.org/wiki/Port_(computer_networking)#Common_port_numbers

I would recommend you to run node apps for development on ports 8000-9000, but you can use any from the registered ports range.


I think you are using a Unix based OS, if that is the case then you can't use any port below 1024 without sudo access.

Also before digging too deep check that the listening port is not being used by any other process.

A quick fix (for development only):

  • sudo node file.js or
  • server.listen(3000); // any number > 1024

For production (never run node on production with root access.)

you have to map the listening port (ex:3000) to 80 using ip tables

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

Just saw this today. User had commented out 127.0.0.1 localhost in their /etc/hosts file, and another network service was resolving localhost to a different IP address not associated with the user's machine.

Solution was to add this line to /etc/hosts

127.0.0.1 localhost

You are using a used port. You must change a port or you must kill a process which is listening on a port. Open terminal and write (example): lsof -i :22 or lsof -i :80 or lsof -i :8000 and kill PID of the process.


How to change the listening PORT in total.js?

  1. in /app/config or /app/config-release or /app/config-debug:
default-ip       : 127.0.0.1
default-port     : 8000

or

// For e.g. Heroku
default-ip       : auto
default-port     : auto
  1. if exist files: release.js or debug.js:
var fs = require("fs");
var options = {};

// options.ip = "127.0.0.1";
// options.port = parseInt(process.argv[2]);
options.port = 8000;
  1. if exists only index.js
// for development:
require('total.js').http('debug', { port: 8000 });

// or for production:
require('total.js').http('release', { port: 8000 });

Thanks and documentation: http://docs.totaljs.com