Skip to content

Instantly share code, notes, and snippets.

@newvertex
Last active September 21, 2016 17:05
Show Gist options
  • Save newvertex/27fc982ad1c3d98beca1c77e576abe1b to your computer and use it in GitHub Desktop.
Save newvertex/27fc982ad1c3d98beca1c77e576abe1b to your computer and use it in GitHub Desktop.
Example: Download file from a url in Node.Js
let http = require('http');
let fs = require('fs');
function downloadFile(fileUrl, outputFileName) {
process.stdout.write(`Downloading: ${fileUrl}\n`);
let output = fs.createWriteStream(outputFileName);
http.get(fileUrl, (res) => {
res.pipe(output);
process.stdout.write(`Downloaded: ${fileSaveName}\n`);
}).on('error', (err) => {
process.stdout.write(`Download error: ${err.message}\n`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment