base64.encode in javascript code example
Example 1: javascript base64 encode
var string = "Hello folks how are you doing today?";
var encodedString = btoa(string);
var decodedString = atob(encodedString);
Example 2: base64 encode node js
> console.log(Buffer.from("Hello World").toString('base64'));
SGVsbG8gV29ybGQ=
> console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'))
Hello World
Example 3: base64 to string and string to base64 javascript decode
let base64ToString = Buffer.from(obj, "base64").toString();
base64ToString = JSON.parse(base64ToString);
let str = 'bmltZXNoZGV1amEuY29t';
let buff = new Buffer(str, 'base64');
let base64ToStringNew = buff.toString('ascii');
let data = 'nimeshdeuja.com';
let buff = new Buffer(data);
let stringToBase64 = buff.toString('base64');
Example 4: javascript encode base64
const encoded = window.btoa('Alireza Dezfoolian');
const decoded = window.atob(encoded);
Example 5: javascript base64 decode
var decodedString = atob(encodedString);