Node.js - Base64

Updated: 2018-12-09

Encoding

var b = new Buffer("JavaScript");
var s = b.toString("base64");
// SmF2YVNjcmlwdA==

Decoding

var b = new Buffer("SmF2YVNjcmlwdA==", "base64");
var s = b.toString();
// JavaScript

To Hex

var b = new Buffer("SmF2YVNjcmlwdA==", "base64");
var s = b.toString("hex");
// 4a617661536372697074

From Hex

var b = new Buffer("4a617661536372697074", "hex");
var s = b.toString("utf8");
// JavaScript