nodejs file to base64 code example
Example 1: nodejs string to base64
> console.log(Buffer.from("Hello World").toString('base64'));
SGVsbG8gV29ybGQ=
> console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'))
Hello World
Example 2: nodejs fs writefile base64url
const fileContents = new Buffer(attachmentResponse.data.data, 'base64')
fs.writeFile(part.filename, fileContents, (err) => {
if (err) return console.error(err)
console.log('file saved to ', part.filename)
})