Categories
JavaScript Answers

How to do base64 encoding in Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *