Last active
February 9, 2019 12:50
-
-
Save alexjpaz/ee3254140c7f15c873f077694286807d to your computer and use it in GitHub Desktop.
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
// async /await | |
const request = async (url) => { | |
let client = require('http'); | |
if(url.startsWith('https')) { | |
client = require('https'); | |
} | |
await new Promise((res, rej) => { | |
client.get(url, (rsp) => { | |
rsp.on('end', () => { | |
if(rsp.statusCode === 200) { | |
res(); | |
} else { | |
rej(); | |
} | |
}); | |
}) | |
.on('error', rej); | |
}); | |
}; | |
const main = async (url) => { | |
try { | |
await request(url); | |
console.log('success'); | |
} catch(e) { | |
console.error(e); | |
process.exit(1); | |
throw e; | |
} | |
}; | |
main("http://gooddgle.com"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment