Skip to content

Instantly share code, notes, and snippets.

@xonecas
Created January 22, 2011 21:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xonecas/791490 to your computer and use it in GitHub Desktop.
Save xonecas/791490 to your computer and use it in GitHub Desktop.
simple wget for node.js
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);
});
@mohsen1
Copy link

mohsen1 commented Mar 9, 2013

Thanks for sharing. Doesn't work with 0.8. createClient is not available anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment