Last active
November 17, 2022 07:42
-
-
Save satiridev/a72b952fb65e071ef0bfb2dab5e6ca5a to your computer and use it in GitHub Desktop.
check-connection-with-nodejs.js
This file contains 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
/** | |
* this file can be used when the pod doesn't have curl or wget and also non root user. | |
* assumed the pod is linux with nodejs installed | |
* | |
* copy the content to memory of your pc/mac, and in the pod, do : | |
* echo "{the-content-of-the-file}" > /tmp/example.js | |
* node /tmp/example.js | |
*/ | |
const https = require('https'); | |
https.get('https://some-server/', (resp) => { | |
let data = ''; | |
// A chunk of data has been received. | |
resp.on('data', (chunk) => { | |
data += chunk; | |
}); | |
// The whole response has been received. Print out the result. | |
resp.on('end', () => { | |
console.log(JSON.parse(data).explanation); | |
}); | |
}).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