Skip to content

Instantly share code, notes, and snippets.

@artiya4u
Created March 22, 2020 13:37
Show Gist options
  • Save artiya4u/f26a1e17c0e9fbfe44738f49a310d49b to your computer and use it in GitHub Desktop.
Save artiya4u/f26a1e17c0e9fbfe44738f49a310d49b to your computer and use it in GitHub Desktop.
Get local IP address in NodeJS
let os = require('os');
module.exports.localIpAddress = () => {
let ifaces = os.networkInterfaces();
for (let dev in ifaces) {
for (let detail of ifaces[dev]) {
if (detail.family === 'IPv4') {
return detail.address;
}
}
}
return undefined;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment