Last active
September 21, 2016 17:05
-
-
Save newvertex/27fc982ad1c3d98beca1c77e576abe1b to your computer and use it in GitHub Desktop.
Example: Download file from a url in 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
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