How to get public ip and local ip address in Raspberry pi 3 using nodejs

Posted By : Chandan Kumar Singh | 28-Dec-2016

In this blog we will fetch Raspberry pi internal ip address and public ip address if it is connected to the internet.

For getting public ip address you can use external-ip library.


 require('external-ip')()(function(err, ip) {
            if (!err) {
            } else {


To get internal ip address.

 var interfaces = require('os').networkInterfaces();
        var addresses = [];
        for (var k in interfaces) {
            for (var k2 in interfaces[k]) {
                var address = interfaces[k][k2];
                if ( === 'IPv4' && address.address !== '' && !address.internal){

Now you can further process the ips according to your requirement.


Related Tags

About Author

Author Image
Chandan Kumar Singh

Chandan is a bright Web Developer with expertise in Java and Spring framework and ORM tools Hibernate. He loves technologies like Blockchain and IoT.

Request for Proposal

Name is required

Comment is required

Sending message..