Created
August 28, 2023 01:30
-
-
Save exmadesu/bbb0c382558a978840c02e738ac4c3a5 to your computer and use it in GitHub Desktop.
NodeJS - One liner to get IP Address of current device
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
// 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