Created
July 26, 2018 07:45
-
-
Save Kirill89/414259718f1b960d475b2de105785d95 to your computer and use it in GitHub Desktop.
nodejs get local IP address
This file contains 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
const os = require('os'); | |
function getLocalIP() { | |
for (const ifaces of Object.values(os.networkInterfaces())) { | |
for (const iface of ifaces) { | |
if (iface.family === 'IPv4' && iface.internal === false) { | |
return iface.address; | |
} | |
} | |
} | |
return '0.0.0.0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment