Skip to content

Instantly share code, notes, and snippets.

@nfort
Last active April 4, 2024 18:28
Show Gist options
  • Save nfort/a29404417452a06ed6e31b3032c7e42b to your computer and use it in GitHub Desktop.
Save nfort/a29404417452a06ed6e31b3032c7e42b to your computer and use it in GitHub Desktop.
Node.js get local ip server
var os = require('os');
var ip = '0.0.0.0';
var ips = os.networkInterfaces();
Object
.keys(ips)
.forEach(function(_interface) {
ips[_interface]
.forEach(function(_dev) {
if (_dev.family === 'IPv4' && !_dev.internal) ip = _dev.address
})
});
console.log(ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment