Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

node check if internet

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()
 
PREVIOUS NEXT
Tagged: #node #check #internet
ADD COMMENT
Topic
Name
4+7 =