Last active
          November 30, 2015 02:55 
        
      - 
      
- 
        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.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // 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