const initial = 'test string';

// encode
const encoded = new Buffer(initial).toString('base64');

// decode
const decoded = new Buffer(encoded, 'base64').toString('ascii');

// check
if (decoded === initial) {
	console.log('Success!');
} else {
	throw new Error('Encoding failed');
}