Preview:
//METHOD 1

const data = 'CodezUp';
console.log('---ORIGINAL-----', data)

// Encode String

const encode = Buffer.from(data).toString('base64')
console.log('\n---ENCODED-----', encode)

// Decode String

const decode = Buffer.from(encode, 'base64').toString('utf-8')
console.log('\n---DECODED-----', decode)

// METHOD 2

// Define the string - btoa will encode
var encodedStringAtoB = "SGVsbG8gV29ybGQh";

// Decode the String
var decodedStringAtoB = atob(encodedStringAtoB);

console.log("final result: ", decodedStringAtoB);


///////////////////////////////

crypto.randomBytes(16, (err, buf) => {
	if (err) {
		console.log("err from random bytes", err);
		return;
	}
	console.log("the random bytes are:", buf.toString("base64"));
	return buf;
});
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter