“NodeJS ES6 String ke Base64” Kode Jawaban

string nodejs ke base64

> console.log(Buffer.from("Hello World").toString('base64'));
SGVsbG8gV29ybGQ=
> console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'))
Hello World
Condemned Centipede

NODEJS BASE64

//--------------- HOW TO ENCODE BASE64 ON NODEJS ----------------------
//create a buffer of the text "Hello World"
var buffer = Buffer.from('Hello World');
//buffer result is: <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>

var string64 = buffer.toString('base64');
// .toString('base64') allow to encode it to base64
// result is: SGVsbG8gV29ybGQ=

// Can be use combined together like these
console.log(Buffer.from('Hello World').toString('base64'));
// result is: SGVsbG8gV29ybGQ=
God Of Coding

NodeJS ES6 String ke Base64

Encoding a string to base64
const buff = Buffer.from("hi readers", "utf8");
const base64 = buff.toString("base64");
console.log(base64); // aGkgcmVhZGVycw==

Decoding a base64 to a string
Similarly, we can decode a base64 encoding to a string like this.
const buff = Buffer.from("aGkgcmVhZGVycw==", "base64");
const str = buff.toString("utf8");
console.log(str); // hi readers
DreamCoder

Jawaban yang mirip dengan “NodeJS ES6 String ke Base64”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya