node alternative to btoa
The Buffer
class in Node.js can be used as an alternative to the btoa
function in the browser. The following steps illustrate how to achieve this:
- Create a buffer from the input string using
Buffer.from(inputString)
. - Encode the buffer using the
toString
method and specifying the encoding type as 'base64'. - The encoded string will be the equivalent of the result obtained from
btoa
in the browser environment.