Last active
April 19, 2020 11:14
-
-
Save Diederikjh/0cc3d1fc232dec35431bfe1da17b711a to your computer and use it in GitHub Desktop.
Node.js simple HTTP getter function
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
/* 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