Amir Saleem
Amir Saleem

Reputation: 3140

How to save Binary Data as a jpg image in NodeJS

I have an api which returns Binary Media Data (The data contains an image), I want to send this data to a file. I am able to do this via CURL command using -o. But I am not able to do the same in node js. Please help.

Upvotes: 0

Views: 674

Answers (1)

Arif Khan
Arif Khan

Reputation: 5069

You may use request module something like following

const fs = require('fs');
const request = require('request');

request
  .get('http://example.com/image.png')
  .pipe(fs.createWriteStream('image.png'))

Upvotes: 3

Related Questions