import dns from 'dns'
const checkInternet = async () => {
return dns.promises
.lookup('google.com')
.then(() => true)
.catch(() => false)
}
// I used it the following way within an async function:
const internet = await checkInternet()