Created
May 30, 2016 20:28
-
-
Save m4munib/4d35ae460f62f8b2eb4d9f2dc412c764 to your computer and use it in GitHub Desktop.
HTTP request helper using Node.js
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
var http = require('http'); | |
function request(options, callback) | |
{ | |
http.request(options, function (response) { | |
var responseBody = ''; | |
response.on('data', function (data) { | |
responseBody += data; | |
}); | |
response.on('end', function () { | |
callback(responseBody); | |
}); | |
response.on('error', function (e) { | |
throw e; | |
}); | |
}).end(); | |
} | |
exports.request = request; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment