Created
January 15, 2012 13:33
-
-
Save syohex/1615874 to your computer and use it in GitHub Desktop.
Simple download with 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 request = require('request'); | |
var fs = require('fs'); | |
var downloadUrl = process.argv[2]; | |
if (typeof donwloadUrl === undefined) { | |
console.log("Usage: request.js URL"); | |
process.exit(1); | |
} | |
request.get({ uri: downloadUrl }, function (error, response, body) { | |
if (!error && response.statusCode === 200) { | |
fs.createWriteStream("output.html", { | |
flags: "w", | |
}).write(body); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment