Skip to content

Instantly share code, notes, and snippets.

@gixxerblade
Last active August 19, 2021 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gixxerblade/63c2ea16c768632cf36a8bcb7a997d72 to your computer and use it in GitHub Desktop.
Save gixxerblade/63c2ea16c768632cf36a8bcb7a997d72 to your computer and use it in GitHub Desktop.
Get local ip address
import { networkInterfaces } from 'os'
const getLocalExternalIP = () => [].concat(...Object.values(networkInterfaces()))
.find((details) => details.family === 'IPv4' && !details.internal)
.address
// or
import { networkInterfaces } from 'os';
const ip = Object.values(networkInterfaces()).flat().find(i => i.family == 'IPv4' && !i.internal).address;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment