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.
๐ŸŒ
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
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ base64-to-image
base64-to-image - npm
var imageInfo = base64ToImage(base64Str,path,optionalObj);
      ยป npm install base64-to-image
    
Published: May 14, 2016
Version: 1.0.2
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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
<input type="file" name="myImage" onChange={this.onImageChange} /> //accpet image file ยท CodeSandbox: https://codesandbox.io/s/gallant-almeida-z6d1x?file=/src/App.js ... In backend, I am using node.js Frontend will send api request to backend with the base64 as the parameter, is it possible to convert it back to image object in backend?
Find elsewhere
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ node-base64-img
node-base64-img - npm
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
๐ŸŒ
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);
๐ŸŒ
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:
๐ŸŒ
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.
๐ŸŒ
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.
Starred by 142 users
Forked by 40 users
Languages: TypeScript 78.2% | JavaScript 21.8% | TypeScript 78.2% | JavaScript 21.8%
๐ŸŒ
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 string to image. image can be created in the formats like jpg, jpeg, png. for this process one module is required and that is โ€˜fsโ€™ which is basically a node module.