The following line will download an image file from a specified url variable:
url
var filename = path.join(__dirname, url.replace(/^.*[\\\\\\/]/, \'
request(url).pipe(fs.createWriteStream(filename)).pipe(writestream);
is the same as this:
var fileStream = fs.createWriteStream(filename); request(url).pipe(fileStream); fileStream.pipe(writestream);
So the issue is that you are attempting to .pipe one WriteStream into another WriteStream.
.pipe
WriteStream