fonini fonini -5 years ago 329
Node.js Question

How to get my external IP address with node.js?

I'm using node.js and I need to get my external IP address, provided by my ISP.
Is there a way to achieve this without using a service like ?

Answer Source was similar to that one.

or you can

    hostname: '',
    path: '/ip.cgi',
    agent: false
    }, function(res) {
    if(res.statusCode != 200) {
        throw new Error('non-OK status: ' + res.statusCode);
    var ipAddress = '';
    res.on('data', function(chunk) { ipAddress += chunk; });
    res.on('end', function() {
        // ipAddress contains the external IP address
    }).on('error', function(err) {
    throw err;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download