Skip to content

Instantly share code, notes, and snippets.

@Diederikjh
Last active April 19, 2020 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diederikjh/0cc3d1fc232dec35431bfe1da17b711a to your computer and use it in GitHub Desktop.
Save Diederikjh/0cc3d1fc232dec35431bfe1da17b711a to your computer and use it in GitHub Desktop.
Node.js simple HTTP getter function
/* I used this with AWS Lambda (running Node 10.x) and [Asynchronous invocation](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html)
to trigger my glitch.com twitter bot. */
var http = require('http');
exports.handler = function(event, context, callback) {
http.get({
host: process.env.HOST,
path: process.env.PATH
}, function(response) {
const { statusCode } = response;
if ( statusCode !== 200) {
callback("error", "Error in function");
}
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
console.log(body);
callback(null, 'Hello from Lambda10');
});
} );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment