Sometimes, we want to do base64 encoding in Node.js.
In this article, we’ll look at how to do base64 encoding in Node.js.
How to do base64 encoding in Node.js?
To do base64 encoding in Node.js, we can use the Buffer.from
method.
For instance, we write
const b = Buffer.from("Hello World").toString('base64')
to call Buffer.from
with the string we want to encode.
Then we convert the returned buffer object to a base64 string by calling toString
with 'base64'
.
Conclusion
To do base64 encoding in Node.js, we can use the Buffer.from
method.