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

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 + '"');
Comment

PREVIOUS NEXT
Code Example
Javascript :: loop through array react native 
Javascript :: nodejs download file 
Javascript :: how to crash with js 
Javascript :: .scrollLeft + 1, 0 
Javascript :: javascript function length 
Javascript :: catch javascript 
Javascript :: send json body http get flutter 
Javascript :: set value lookup javascript dynamics 365 
Javascript :: return an object from an array javascript 
Javascript :: discord.js timeout 
Javascript :: loop object array 
Javascript :: sequelize update sql 
Javascript :: Environment key "jest/globals" is unknown - react 
Javascript :: How to Submit Forms and Save Data with React.js 
Javascript :: adding function to objects js 
Javascript :: arry to object using reduce 
Javascript :: javascript set object key by variable 
Javascript :: usecallback hook react 
Javascript :: react lottie 
Javascript :: js alert new line 
Javascript :: javascript crash course 
Javascript :: JavaScript for loop Display Sum of n Natural Numbers 
Javascript :: how to disable link in react 
Javascript :: vue 3 create component 
Javascript :: capitalize all letters jquery 
Javascript :: componentwillreceiveprops hooks 
Javascript :: c# razor for loop javascript 
Javascript :: nuxt 3 add plugin 
Javascript :: concat array javascript 
Javascript :: javascript promise.all 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =