This is how I did it using stream and pipe , (I used express , but you may not need this)
var express = require('express'); var app = express(); var filesystem = require('fs'); var https = require('https'); var download = function(url, dest, cb) { var file = filesystem.createWriteStream(dest); var request = https.get(url, function(httpResponse) { httpResponse.pipe(file); file.on('finish', function() { console.log("piping to file finished") file.close(cb);
When I start using node server.js and click on url localhost:3000/image , it will download and save the file in porcupine.png in the base directory.
prayagupd
source share