IPv6 with NodeJS

As there are just a few new ipv4 address left in the pool and even those will be exhausted in under a week (6 days left, checked right now) the switch to IPv6 will be necessary soon.

My current ISP does not offer any real IPv6 connection and not even my router can handle IPv6 (yet) there's currently no (good & easy) way for me to use IPv6 from here.

But aside from that fact, my vserver running this blog now has IPv6 addresses (and can even get more).

v6.fnordig.de is available via IPv6, but there's no service running yet. I will make this blog accessible via IPv6 soon.

As I really like node.js I wanted to know how it handles v6 addresses and found this article on code.danyork.com.

It's as easy as this:

var http = require('http');
var server = http.createServer(function (request, response) {
   response.writeHead(200, {"Content-Type":"text/plain"});
   response.end ("Hello World!\n");
   console.log("Got a connection");
});
server.listen(80, "2a01:xxxx:xxxx:xxxx::2");
console.log("Server running on localhost at port 80");

Just pass the IPv6 address as the host parameter to server.listen. This listens on just one IP; it's possible to listen on all, similar to the 0.0.0.0 for IPv4:

server.listen(80, "::0");

Other things worth to mention:

So get going and use IPv6!