Skip to content

Instantly share code, notes, and snippets.

@cold-coder
Last active November 30, 2015 02:55
Show Gist options
  • Save cold-coder/899a29eadd1dd2c3089e to your computer and use it in GitHub Desktop.
Save cold-coder/899a29eadd1dd2c3089e to your computer and use it in GitHub Desktop.
Check Internet access available in node.js, use book.douban.com to test in this case.
// require('dns').resolve('book.douban.com', function(err) {
// if (err){
// console.log('Oops! Cannot access Douban');
// }
// else{
// console.log('Have Internet Access');
// }
// });
require('http').get("book.douban.com", function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment