Skip to content

Instantly share code, notes, and snippets.

@ClementParis016
Created September 30, 2017 16:37
Show Gist options
  • Save ClementParis016/af453e7236bffaeabc6e3bc10a56fa7c to your computer and use it in GitHub Desktop.
Save ClementParis016/af453e7236bffaeabc6e3bc10a56fa7c to your computer and use it in GitHub Desktop.
Convert a base64 image to a file with Node.js
const fs = require('fs');
const rawBase64 = ''; // typically 'data:image/png;base64,.......'
const [, ext, data] = rawBase64.match(/^data:image\/([a-z]+);base64,(.*)$/);
fs.writeFileSync(`image.${ext}`, data, 'base64');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment