You can decode the base64 image using following method .

EDITED

To strip off the header

let base64String = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA'; // Not a real image
// Remove header
let base64Image = base64String.split(';base64,').pop();

To write to a file

import fs from 'fs';
fs.writeFile('image.png', base64Image, {encoding: 'base64'}, function(err) {
    console.log('File created');
});

Note :- Don’t forget the {encoding: 'base64'} here and you will be good to go.

Answer from Pushprajsinh Chudasama on Stack Overflow
🌐
npm
npmjs.com › package › base64-to-image
base64-to-image - npm
Decode base64 to image and save the image to disk.
      » npm install base64-to-image
    
Published   May 14, 2016
Version   1.0.2
Author   helenys
🌐
npm
npmjs.com › package › base64-img
base64-img - npm
February 13, 2018 - Convert img to base64, or convert base64 to img · var base64Img = require('base64-img'); npm install base64-img --save · mocha · Convert image file to image base64 data · {string} filename required The image path · {function} callback(err, ...
      » npm install base64-img
    
Published   Feb 13, 2018
Version   1.0.4
🌐
npm
npmjs.com › package › convert-base64-to-image
convert-base64-to-image - npm
January 16, 2022 - import { converBase64ToImage } from 'convert-base64-to-image' const base64 = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//' const pathToSaveImage = './public/image.png' const path = converBase64ToImage(base64, pathToSaveImage) //returns path /public/image.png
      » npm install convert-base64-to-image
    
Published   Jan 16, 2022
Version   0.0.16
Author   Patrick
🌐
npm
npmjs.com › package › b64-to-image
b64-to-image - npm
Convert Base64 string to Image. Latest version: 1.0.2, last published: 7 years ago. Start using b64-to-image in your project by running `npm i b64-to-image`. There are 2 other projects in the npm registry using b64-to-image.
      » npm install b64-to-image
    
Published   Jan 16, 2019
Version   1.0.2
Author   Ritesh Gandhi
🌐
Medium
medium.com › @programminglover › how-to-convert-base64-to-image-file-9d3db4e01885
How to convert base64 to image file? | by Programming Lover | Medium
July 5, 2019 - Here we are going to convert base64 ... ok and if not then just install this module by typing this command on your terminal :- npm install fs ·...
🌐
npm
npmjs.com › search
base64-to-image - npm search
`b64toBlob(b64Data: string, ... 7.1.3, a year ago108 dependents licensed under $MIT ... Generates an image from a DOM node using HTML5 canvas and SVG....
🌐
npm
npmjs.com › package › node-base64-image
node-base64-image - npm
May 10, 2026 - Easily encode images (from URLs or local files) to Base64 strings or Buffer objects, and decode them back into image files.
      » npm install node-base64-image
    
Published   May 10, 2026
Version   3.0.0
🌐
npm
npmjs.com › package › image-to-base64
image-to-base64 - npm
Generate a base64 code from an image through a URL or a path.
      » npm install image-to-base64
    
Published   Apr 09, 2021
Version   2.2.0
Find elsewhere
🌐
GitHub
github.com › patrickkabwe › base64-to-image
GitHub - patrickkabwe/base64-to-image: Node package that helps you to convert base64 string created by javascript file reader to image downloadable file
import { converBase64ToImage } from 'convert-base64-to-image' const base64 = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//' const pathToSaveImage = './public/image.png' const path = converBase64ToImage(base64, pathToSaveImage) //returns path /public/image.png
Author   patrickkabwe
🌐
npm
npmjs.com › package › node-base64-img
node-base64-img - npm
A base64-image converter and vice-versa for node with modern ES6. Convert your base64 strings to images or convert your images to base64 string. Build with native support for async/await and promises.
      » npm install node-base64-img
    
Published   Dec 29, 2022
Version   2.0.0
🌐
DEV Community
dev.to › dnature › convert-a-base64-data-into-an-image-in-node-js-3f88
Convert a Base64 data into an Image in Node.js - DEV Community
December 17, 2021 - yarn add jimp # or npm install jimp · You can simply reduce the quality of your image by 50% with just a few lines of code. I am going to use a base64 string as my data source.
🌐
GitHub
github.com › dopecodez › base64-image
GitHub - dopecodez/base64-image: A base64 to image and vice versa converter using latest ES6. · GitHub
Build with native support for async/await and promises. Supports png, jpg, jpeg and gif images. Newly released and actively maintained. Small unpacked size. $ npm install node-base64-img ·
Starred by 13 users
Forked by 3 users
Languages   TypeScript
🌐
npm
npmjs.com › search
keywords:base64-to-image - npm search
This package efficiently converts base64-encoded strings into image files enabling easy display of image within your application
🌐
npm
npmjs.com › package › base64image
base64image - npm
December 18, 2015 - var options = {filename: 'test', filePath: './tmp/uploads'}; var imageData = new Buffer('/9j/4AAQSkZJRgABAQAAAQABAAD...', 'base64'); base64.base64decoder(imageData, options, function (err, saved) { if (err) { console.log(err); } console.log(saved); }); ... options (object) - contains the 'filename' property; this will be the written image file. Also, you can specify a filePath which takes a directory path to write the file to.
      » npm install base64image
    
Published   Dec 18, 2015
Version   0.1.1
🌐
npms
npms.io › search
convert-image-base64
npms was built to empower the javascript community by providing a better and open sourced search for node modules.
🌐
Medium
medium.com › @divinehycenth8 › convert-a-base64-data-into-an-image-in-node-js-d82136576e35
Convert a Base64 data into an Image in Node.js | by Divine Hycenth | Medium
November 15, 2020 - yarn add jimp # or npm install jimp · You can simply reduce the quality of your image by 50% with just a few lines of code. I am going to use a base64 string as my data source.
🌐
Npmdoc
npmdoc.github.io › node-npmdoc-base64-img › build › apidoc.html
function - base64-img.
... ```js var url = 'http://../demo.png'; base64Img.requestBase64(url, function(err, res, body) { }); ``` ### .img(data, destpath, name, callback) Convert image base64 data to image * {string} ``data`` required Image base64 data * {string} ``destpath`` required Dest path, if the destpath is ...
🌐
GitHub
github.com › karan1149 › base64-image-upload
GitHub - karan1149/base64-image-upload: NPM package for uploading image data to APIs with restrictive interfaces.
This is a simple NPM package for uploading (using a POST request) image data to APIs with restrictive interfaces. Specifically, there is a scarcity of documentation online on how to upload base64-encoded images to APIs that only accept binary ...
Starred by 7 users
Forked by 2 users
Languages   JavaScript 100.0% | JavaScript 100.0%