'Node.js get a computer network ip format usable in an external LAN post request

The code below is built to fetch the network ip of a computer in a LAN network.

I need to identify the computer's network ip format like '192.1.xx.x.x59' that can be usable when making an external LAN post request.

The problem is the code keeps returning '0.0.0.0' as the network ip.

Could you please help me spot the problem with this code.

Thanks in advance!


function getIPAddress() {
    var interfaces = require('os').networkInterfaces();
    for (var devName in interfaces) {
      var iface = interfaces[devName];
  
      for (var i = 0; i < iface.length; i++) {
        var alias = iface[i];
        if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal)
          return alias.address;
      }
    }
    return '0.0.0.0';
}

console.log(getIPAddress());



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source