Answers for "nodejs string to base64"

9

nodejs string to base64

> console.log(Buffer.from("Hello World").toString('base64'));
SGVsbG8gV29ybGQ=
> console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'))
Hello World
Posted by: Guest on February-18-2020
1

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('base64');
// .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"
Posted by: Guest on July-29-2021
-2

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 + '"');
Posted by: Guest on March-01-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language