Created
April 10, 2019 19:02
-
-
Save romfrolov/e9436cc1271adaa0a9d0bf8f4097d12d to your computer and use it in GitHub Desktop.
Check internet connection in Nodejs.
This file contains 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
'use strict'; | |
const dns = require('dns').promises; | |
/** | |
* Check connection to internet. | |
* | |
* @return {Promise<Boolean>} Whether there is connection to internet or not. | |
*/ | |
exports.checkInternet = function checkInternet() { | |
return dns.lookup('google.com') | |
.then(() => true) | |
.catch(() => false); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment