DEV Community

Steven Liao
Steven Liao

Posted on

11 3

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?

nextjs tutorial video

📺 Youtube Tutorial Series

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay