nyc-bookstores/node_modules/hasinternet/index.js

12 lines
305 B
JavaScript
Raw Normal View History

2013-05-27 20:45:59 +00:00
var dns = require('dns')
module.exports = hasInternet
function hasInternet(cb) {
if (process.browser) return cb(false, navigator.onLine)
dns.lookup('www.google.com', function(err, addresses) {
if (err) return cb(err, false) // an error, no www
return cb(false, true) // no error, has www
})
}