Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs string to base64

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

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=
Comment

nodejs base64

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

var string64 = buffer.toString('ascii');
// .toString('ascii') allow to decode base64
// result is: "Hello World"

// Can be use combined together like these
console.log(Buffer.from('SGVsbG8gV29ybGQ=', 'base64').toString('ascii'));
// result is: "Hello World"
Comment

NODEJS ES6 STRING TO 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
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get a user input in js 
Javascript :: inline styling in react 
Javascript :: vuejs get value of checkbox group 
Javascript :: remove selected js 
Javascript :: datatables server side 
Javascript :: react compress image 
Javascript :: get element by xpath 
Javascript :: how to hide ascending descending icons in datatable js 
Javascript :: create a loop that runs through each item in an array 
Javascript :: bind an event to dom element angular 
Javascript :: active navbar in page reactjs 
Javascript :: javascript file on select 
Javascript :: replace jquery 
Javascript :: how to design an api node js 
Javascript :: types of loops in javascript 
Javascript :: downgrade node version 
Javascript :: javascript listen array change 
Javascript :: javascript get nested element 
Javascript :: javascript range of integers 
Javascript :: puppeteer set download path 
Javascript :: disable button 
Javascript :: return a date time object in yyyy-mm-dd hr:min:sec 
Javascript :: jquery post form async 
Javascript :: javascript detect tab leave 
Javascript :: p5js import typescript 
Javascript :: linux cli format json 
Javascript :: date in react js 
Javascript :: make a flat object from object of object list 
Javascript :: get random element from string array java 
Javascript :: select2 find option by text 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =