Skip to content

Instantly share code, notes, and snippets.

@JokingChicken
Last active June 17, 2018 20:57
Show Gist options
  • Save JokingChicken/0c5ce03085bcd78c3d81f87a9a63a8a6 to your computer and use it in GitHub Desktop.
Save JokingChicken/0c5ce03085bcd78c3d81f87a9a63a8a6 to your computer and use it in GitHub Desktop.
Base64 Encoding and Decoding in Node
//Here is how you encode normal text to base64 in Node.js:
var b = new Buffer('JavaScript');
var s = b.toString('base64');
// SmF2YVNjcmlwdA==
//And here is how you decode base64 encoded strings:
var b = new Buffer('SmF2YVNjcmlwdA==', 'base64')
var s = b.toString();
// JavaScript
//Let's encode a base64 encoded string to hex:
var b = new Buffer('SmF2YVNjcmlwdA==', 'base64')
var s = b.toString('hex');
// 4a617661536372697074
//Now decode it to something humans can read:
var b = new Buffer('4a617661536372697074', 'hex')
var s = b.toString('utf8');
// JavaScript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment