Skip to content

Instantly share code, notes, and snippets.

@Kirill89
Created July 26, 2018 07:45
Show Gist options
  • Save Kirill89/414259718f1b960d475b2de105785d95 to your computer and use it in GitHub Desktop.
Save Kirill89/414259718f1b960d475b2de105785d95 to your computer and use it in GitHub Desktop.
nodejs get local IP address
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