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 :: jquery get element by class and data attribute 
Javascript :: get text selected option jquery 
Javascript :: await async sleep 
Javascript :: import map in angular 
Javascript :: javascript create element with attributes 
Javascript :: install moment in goole dev console 
Javascript :: javascript change comma to dot 
Javascript :: mayoe que menor que 
Javascript :: javascript biggest number 
Javascript :: minus month javascript date 
Javascript :: how to change background image url in javascript 
Javascript :: js wait sleep 
Javascript :: css in console.log 
Javascript :: javascript get random floating number 
Javascript :: npm remove dev dependencies from node_modules 
Javascript :: req.body is undefined 
Javascript :: convert english number to bangla javascript 
Javascript :: set width screen angular 
Javascript :: cypress clear session storage 
Javascript :: react native disable warnings 
Javascript :: convert a string to html element in js 
Javascript :: count items in div jquery 
Javascript :: check if parameter is array javascript 
Javascript :: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. 
Javascript :: how to submit using checkbox 
Javascript :: count all elements with class jquery 
Javascript :: is email js 
Javascript :: get query from url react router dom v6 
Javascript :: jquery form serialized data 
Javascript :: remove last 3 characters from string javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =