Advertisement
adamatti

Check httpStatusCodes on an url

Sep 9th, 2022
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import got from 'got';
  2. import notifier from 'node-notifier';
  3.  
  4. const url = "";
  5.  
  6. function msleep(n) {
  7.   Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n);
  8. }
  9. function sleep(n) {
  10.   msleep(n*1000);
  11. }
  12.  
  13. const log = (msg) => {
  14.   console.log(new Date(), msg)
  15. }
  16.  
  17. const main = async () => {
  18.   log("Running");
  19.   while(true) {
  20.     const response = await got(url);
  21.     const {statusCode} = response;
  22.     if (statusCode !== 200){
  23.       notifier.notify(`Invalid status code: ${statusCode}`)
  24.       log(`Result: ${statusCode}`);
  25.     }    
  26.  
  27.     sleep(1);
  28.   }
  29. }
  30.  
  31. main();
Tags: nodejs checks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement