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?

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more