convert buffer to base64 code example
Example 1: nodejs string to base64
> console.log(Buffer.from("Hello World").toString('base64'));
SGVsbG8gV29ybGQ=
> console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'))
Hello World
Example 2: convert buffer to base64 javascript
var buffer = Buffer.from('hello');
var string64 = buffer.toString('base64');
Example 3: buffer from base64
const b64string = ;
const buf = Buffer.from(b64string, 'base64');
Example 4: Encoding and Decoding Base64 Strings in Node.js
'use strict';
let data = 'stackabuse.com';
let buff = new Buffer(data);
let base64data = buff.toString('base64');
console.log('"' + data + '" converted to Base64 is "' + base64data + '"');