Created
July 23, 2020 05:40
-
-
Save joe-oli/fa500d0895c6e4b1443074a1e148d06c to your computer and use it in GitHub Desktop.
Http-Client using Node.exe only
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
/*========================= | |
USAGE: >node makeHttpReq.js | |
=========================== */ | |
const INTERVAL_MINS = 15; | |
const http = require('http'); //define the native (to node) http module, where you can make a request; | |
const url = "http://YOUR/SERVER/HERE/Path/To/Your/Route.aspx"; | |
callbackFN(); //MAKE ONE CALL, then set up periodic calls... | |
let requestLoop = setInterval( callbackFN, INTERVAL_MINS*60*1000); | |
console.log(`Node looper running every ${INTERVAL_MINS} Minute...`); | |
function callbackFN() { | |
http.get(url, (resp) => { | |
let data = ''; | |
// A chunk of data has been received; i.e. the node http-request is quite low-level, you have to receive response in chunks !! | |
resp.on('data', (chunk) => { | |
data += chunk; | |
}); | |
// The whole response has been received. Print out the result. | |
resp.on('end', () => { | |
console.log('received:', data); //JSON.parse() | |
console.log('------------------------------'); | |
console.log('waiting for next loop...'); | |
}); | |
}).on("error", (err) => { | |
console.log("Error: " + err.message); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment