UNPKG

localanywhere

Version:

Share your localhost with QR codes for easy mobile testing

16 lines (13 loc) 408 B
const os = require('os'); function getLocalIp() { const interfaces = os.networkInterfaces(); for (const iface of Object.values(interfaces)) { for (const alias of iface) { if (alias.family === 'IPv4' && !alias.internal) { return alias.address; } } } return '127.0.0.1'; // Fallback to localhost if no network interface found } module.exports = getLocalIp;