Skip to content

Instantly share code, notes, and snippets.

@ryanhanwu
Forked from xonecas/wget
Created August 6, 2012 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanhanwu/3269237 to your computer and use it in GitHub Desktop.
Save ryanhanwu/3269237 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', '/flyworld.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