javascript - Is there a node way to detect if a network interface comes online? -


i have looked @ os module , ip module @ telling me current ip address of system not if new 1 comes online or goes offline. know can accomplish problem using udev rules (i'm on ubuntu) hoping way using node. how go discovering if network interface started?

you setup listener using process.nexttick , see if set of interfaces has changed since last time. if so, send out updates listeners.

'use strict';  let os = require('os');  // track listeners , provide way of adding new 1 // want put kind of module // can used in various places let listeners = []; function onchange(f) {     if (listeners.indexof(f) === -1) {         listeners.push(f);     } }  let oldinterfaces = []; process.nexttick(function checkinterfaces() {     let interfaces = os.networkinterfaces();      // quick , dirty way of checking differences     // not efficient     if (json.stringify(interfaces) !== json.stringify(oldinterfaces)) {         listeners.foreach((f) => f(interfaces));         oldinterfaces = interfaces;     }      // continue check again on next tick     process.nexttick(checkinterfaces); });  // print out current interfaces whenever there's change onchange(console.log.bind(console));