Last active
April 4, 2024 18:28
-
-
Save nfort/a29404417452a06ed6e31b3032c7e42b to your computer and use it in GitHub Desktop.
Node.js get local ip server
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
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