Reputation: 3109
I am using the request
module in node to make an http request. How do I read the response content of that request so that I can make a programmatic decision based on the response?
gulp.task("run-server-tests", function(){
var responseJson = request("http://myurl/run-server-tests")
plugins.util.log(responseJson); // not sure how to get at the response json
});
Upvotes: 0
Views: 1420
Reputation: 342
request allows you to use callback function, see more detail
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the Google homepage.
}
})
Upvotes: 1