The following line will download an image file from a specified url
variable:
var filename = path.join(__dirname, url.replace(/^.*[\\\\\\/]/, \'
// create 'fs' module variable
var fs = require("fs");
// open the streams
var readerStream = fs.createReadStream('inputfile.txt');
var writerStream = fs.createWriteStream('outputfile.txt');
// pipe the read and write operations
// read input file and write data to output file
readerStream.pipe(writerStream);