network.ts
1 import os from 'os' 2 3 export function localIP(): string { 4 for (const interfaces of Object.values(os.networkInterfaces())) { 5 if (!interfaces) continue 6 for (const network of interfaces) { 7 if (network.family === 'IPv4' && !network.internal) return network.address 8 } 9 } 10 return 'localhost' 11 }