TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of IncomingMessage

Viewed 1370

I have this nodejs code in a cli script. I'm trying to download some images from an array of links but I get always this error:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of IncomingMessage

this is the code:

    imagesLinks.forEach( (link) => {
      let filename = path.basename(link);
      let outputDir = path.format({dir: __dirname, base: `/dadini/${filename}`});
      https.get(link, (res) => {
        fs.writeFileSync(outputDir, res);
      });
    });  

How I can get the image from the link correctly to pass it to the writeFileSync function?

0 Answers
Related