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
🌐
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 - You need to first convert your string into Buffer before saving it as a real image otherwise, you're going to run into issues. ... Luckily, Node.js provides a native module called Buffer that can be used to perform Base64 encoding and decoding.
🌐
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 - You need to first convert your string into Buffer before saving it as a real image otherwise, you’re going to run into issues. ... Luckily, Node.js provides a native module called Buffer that can be used to perform Base64 encoding and decoding.
🌐
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 › base64-to-image
base64-to-image - npm
var base64Str = "Add valid base64 str"; var path ='put a valid path where you want to save the image'; var optionalObj = {'fileName': 'imageFileName', 'type':'png'}; base64ToImage(base64Str,path,optionalObj); Note base64ToImage function returns ...
      » npm install base64-to-image
    
Published   May 14, 2016
Version   1.0.2
Author   helenys
🌐
GitHub
gist.github.com › sid24rane › bdf557cf9f835181a994439da0b5b82a
Node.js Base64 Encode Decode -> Image · GitHub
To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ... 'use strict'; // node v8.11.3 const Buffer = require('buffer').Buffer; const path = require('path'); const fs = require('fs'); /** * @param {string} filename */ function encode_base64(filename) { fs.readFile(path.join(__dirname, '/public/', filename), function(error, data) { if (error) { throw error; } else { let buf = Buffer.from(data); let base64 = buf.toString('base64'); // console.log('Base64 ' + filename + ': ' + base64); return base64; } }); } /** * @param {
🌐
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 › 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
Find elsewhere
🌐
GitHub
gist.github.com › miguelmota › 4e9864f182c053d7a51d
Base64 to PNG in Node.js · GitHub
Base64 to PNG in Node.js. GitHub Gist: instantly share code, notes, and snippets.
🌐
Google Groups
groups.google.com › g › nodejs › c › n-wpLFfjZH8
Convert Base64 Encoded String Back to an Image and Write to Disk
November 23, 2010 - Sorry, seems I didn't get your original e-mail. The below works for me, result is an image of a keyboard. var data = /* snip */; buffer = new Buffer(data, 'base64'); console.log(data.length, buffer.length); require('fs').writeFileSync('image.jpg', buffer, 0, buffer.length);
🌐
Stack Overflow
stackoverflow.com › questions › 67995950 › nodejs-how-to-convert-base64-image-to-image-object
node.js - nodejs - how to convert base64 image to image object - Stack Overflow
In frontend, I am using React. The input accept the image file ... onImageChange = event => { if (event.target.files && event.target.files[0]) { let img = event.target.files[...
🌐
CodeBlocQ
codeblocq.com › 2016 › 04 › Convert-a-base64-string-to-a-file-in-Node
Convert a base64 string to a file in Node - CodeBlocQ
April 11, 2016 - There might be scenarios where you need to convert an base64 string back to a file. This article will show you how. As an example, a base64 string representation of a png image looks like:
🌐
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 - var base64 = ‘iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==’; ... By Default it will save the image on your root directory.But if you want to save the image in your specified directory then you can use it like :-
🌐
ItSolutionstuff
itsolutionstuff.com › post › node-js-convert-image-file-to-base64-string-exampleexample.html
Node JS Convert Image File to Base64 String Example - ItSolutionstuff.com
March 24, 2021 - In this example, you will learn node js convert image file to base64. you will learn node js convert base64 string to image. you can see node js image to base64 string convert.
🌐
Medium
medium.com › techdevathe › how-to-convert-a-base-64-string-into-an-actual-image-zip-file-in-node-js-dbc97086a7d3
How to Convert a Base 64 String into an Actual Image Zip File in Node JS | by lavanya k | Techdevathe | Medium
April 30, 2023 - // Specify the base64-encoded image string const base64ImageString = 'base64-encoded-image-string';// Decode the base64 string and write the image to a file const imageBuffer = Buffer.from(base64ImageString, 'base64'); fs.writeFileSync('image.jpg', ...
🌐
npm
npmjs.com › package › base64-img
base64-img - npm
February 13, 2018 - Convert image base64 data to image · {string} data required Image base64 data · {string} destpath required Dest path, if the destpath is root, pass empty string · {string} name required The image's filename · {function} callback(err, filepath) required ·
      » npm install base64-img
    
Published   Feb 13, 2018
Version   1.0.4