rats-search/src/background/checkInternet.js
2018-07-17 12:18:30 +03:00

10 lines
304 B
JavaScript

// https://stackoverflow.com/questions/15270902/check-for-internet-connectivity-in-nodejs
module.exports = function checkInternet(cb) {
require('dns').lookup('google.com',function(err) {
if (err && (err.code == "ENOTFOUND" || err.code == "EAI_AGAIN")) {
cb(false);
} else {
cb(true);
}
})
}