To write base64 image-file with Node, we call writeFile.
For instance, we write
const image = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAA..kJggg==";
const data = image.replace(/^data:image\/\w+;base64,/, "");
fs.writeFile(fileName, data, { encoding: "base64" }, (err) => {
//...
});
to call writeFile with the MIME type part of the base64 string removed.
And we set encoding to 'base64' to convert the base64 string to binary content.
We get errors from err in the callback.