If you're trying to use btoa
in Node, you'll notice that it is deprecated. It'll suggest you to use the Buffer
class instead.
Here's how you replicate the same functionality using Buffer
:
// Deprecated
btoa(string)
// Buffer equivalent
Buffer.from(string).toString('base64')
Top comments (2)
// right way to encode a string
Buffer.from(string, 'binary').toString('base64')
why is this the right way?