I have a Node.js app. I am trying to write a utility app to do some network detection. I'm creating this app just to learn more about Node.
In this app, I want to see if a) my computer is online and b) if it can reach the internet. If I was doing this in the browser, I could use navigator.onLine
, then attempt to reach a website. However, that's not an option in Node.
I looked at the OS module's networkInterfaces method, however, that doesn't seem to have what I need. For example, if you go to a Starbucks, you can be "online" but not actually reach the internet until you agree to the terms of service for their network. I've been testing this scenario by toggling airplane mode on my machine. Whether Airplane Mode is on or off, the networkInterfaces
method returns the same thing.
How can I recreate the navigator.onLine
functionality in Node?