DEV Community

Steven Liao
Steven Liao

Posted on

btoa replacement in Node.js

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')
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
screeeen profile image
Miguel

// right way to encode a string
Buffer.from(string, 'binary').toString('base64')

Collapse
 
ovidiu141 profile image
Ovidiu Miu

why is this the right way?