Skip to content

Instantly share code, notes, and snippets.

@inadarei
Created January 6, 2013 04:11
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save inadarei/4465153 to your computer and use it in GitHub Desktop.
Save inadarei/4465153 to your computer and use it in GitHub Desktop.
base64 encode/decode in Node.js
var url = "http://cdn1.giltcdn.com/images/share/uploads/0000/0001/7250/172502872/420x560.jpg";
var encoded = new Buffer(url).toString('base64');
var decoded = new Buffer(encoded, 'base64').toString('ascii')
console.log(encoded);
console.log(decoded);
@RoToRx88
Copy link

RoToRx88 commented May 2, 2019

The usage of new Buffer() is deprecated. You could use instead new Buffer.from(url).toString('base64')

@chiragzq
Copy link

I know its probably a typo, but I want to clarify that it should be Buffer.from(url).toString('base64') without the new keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment