Skip to content

Instantly share code, notes, and snippets.

@satiridev
Last active November 17, 2022 07:42
Show Gist options
  • Save satiridev/a72b952fb65e071ef0bfb2dab5e6ca5a to your computer and use it in GitHub Desktop.
Save satiridev/a72b952fb65e071ef0bfb2dab5e6ca5a to your computer and use it in GitHub Desktop.
check-connection-with-nodejs.js
/**
* 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