os.networkInterfaces()
Returns an object describing the network interfaces assigned to the host.
Syntax
os.networkInterfaces() Returns
object — Interface names mapped to arrays of address objects.
Examples
import { networkInterfaces } from 'node:os';
const nets = networkInterfaces();
console.log(Object.keys(nets));
Output
[ 'lo0', 'en0' ]
import { networkInterfaces } from 'node:os';
for (const addrs of Object.values(networkInterfaces())) {
for (const a of addrs) {
if (a.family === 'IPv4' && !a.internal) console.log(a.address);
}
}
Output
192.168.1.42
Notes
Filter out `internal` (loopback) entries and check `family` for
`'IPv4'`/`'IPv6'` to find the LAN address. The list reflects the
state at call time and can change.