Last active
November 25, 2019 20:44
-
-
Save savokiss/96de34d4ca2d37cbb8e0799798c4c2d3 to your computer and use it in GitHub Desktop.
Node.js get local IP address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment