var base64Data = req.rawBody.replace(/^data:image/png;base64,/, "");
require("fs").writeFile("out.png", base64Data, 'base64', function(err) {
console.log(err);
});
var fs = require('fs');
var imageAsBase64 = fs.readFileSync('./your-image.png', 'base64');
const fs = require('fs')
// base64 data to buffer
var buffer = Buffer.from('your-base64-data','base64')
// buffer to image
fs.writeFileSync('file-name.jpg',buffer)
var fs = require('fs');
// function to encode file data to base64 encoded string
function base64_encode(file) {
// read binary data
var bitmap = fs.readFileSync(file);
// convert binary data to base64 encoded string
return new Buffer(bitmap).toString('base64');
}
const fs = require('fs');
const contents = fs.readFileSync('/path/to/file.jpg', {encoding: 'base64'});
const fs = require('fs').promises;
const contents = await fs.readFile('/path/to/file.jpg', {encoding: 'base64'});