Skip to content

Instantly share code, notes, and snippets.

@exmadesu
Created August 28, 2023 01:30
Show Gist options
  • Save exmadesu/bbb0c382558a978840c02e738ac4c3a5 to your computer and use it in GitHub Desktop.
Save exmadesu/bbb0c382558a978840c02e738ac4c3a5 to your computer and use it in GitHub Desktop.
NodeJS - One liner to get IP Address of current device
// One liner to get IP Address of current device
Object.values(require('os').networkInterfaces()).reduce((r, list) => r.concat(list.reduce((rr, i) => rr.concat(i.family==='IPv4' && !i.internal && i.address || []), [])), []);
// The return should be an Array
// Source = https://stackoverflow.com/questions/3653065/get-local-ip-address-in-node-js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment