Skip to content

Instantly share code, notes, and snippets.

@romfrolov
Created April 10, 2019 19:02
Show Gist options
  • Save romfrolov/e9436cc1271adaa0a9d0bf8f4097d12d to your computer and use it in GitHub Desktop.
Save romfrolov/e9436cc1271adaa0a9d0bf8f4097d12d to your computer and use it in GitHub Desktop.
Check internet connection in Nodejs.
'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