-
-
Save xonecas/791490 to your computer and use it in GitHub Desktop.
simple wget for node.js
This file contains 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
require('http'); | |
function wget (host, path, https, callback) { | |
var port = (https)? 443: 80, | |
client = http.createClient(port, host, https), | |
request = client.request('get', path, { 'host': host }), | |
response_body = ''; | |
request.end(); | |
request.on('response', function (response) { | |
response.on('data', function (chunk) { | |
response_body += chunk; | |
}); | |
response.on('end', function () { | |
callback(response_body); | |
}); | |
}); | |
} | |
wget('github.com', '/xonecas.atom', true, function (atom) { | |
console.log(atom); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing. Doesn't work with
0.8
.createClient
is not available anymore.