The Node btoa() and atob() functions are the only ones that have been deprecated. However, if you're working on the DOM code (front-end) and see this deprecated notice, you can use the window object to get around it.

window.atob()

For more info

Answer from Kamal Thennakoon on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › btoa
Window: btoa() method - Web APIs | MDN
Strings in JavaScript are encoded as UTF-16, so this means each character must have a code point less than 256, representing one byte of data. An ASCII string containing the Base64 representation of stringToEncode. ... The string contained a character that did not fit in a single byte. See "Unicode strings" below for more detail. ... const encodedData = window.btoa("Hello, world"); // encode a string const decodedData = window.atob(encodedData); // decode the string
🌐
W3Schools
w3schools.com › jsref › met_win_btoa.asp
Window btoa() Method
The btoa() method uses the "A-Z", "a-z", "0-9", "+", "/" and "=" characters to encode the string.
Discussions

What does **b** and **a** in `btoa()` mean?
B is a stand in for binary. A is a stand in for ASCII. So btoa is Binary to ASCII, and atob is ASCII to binary. More on reddit.com
🌐 r/learnjavascript
6
20
August 10, 2019
How to use "btoa" (and "atob") in Javascript? - Feature Suggestions - Fuse Community
Ive tried to base64 encode a string in javascript by using “btoa(mystring)”. “StackTrace: ReferenceError: btoa is not defined” Am I missing a require? More on forums.fusetools.com
🌐 forums.fusetools.com
0
September 26, 2015
Using `btoa` and `atob` for faster Base64 encoding and decoding
Modern browsers support the atob and btoa functions for Base64 encoding and decoding respectively. I just threw together some benchmarks that demonstrate this could be an area for improved performa... More on github.com
🌐 github.com
5
January 28, 2017
Function - how to do btoa javascript function
Hi, for an HTTP request, I need to use btoa to base64 encode the token. As btoa is part of the window class which does not seem to be available - how can I do this instead? Btw, a little “bug” here: If I create an expression for a HTTP Request variable, btoa works in the preview (I guess ... More on community.n8n.io
🌐 community.n8n.io
4
0
March 12, 2021
Top answer
1 of 4
176

The Node btoa() and atob() functions are the only ones that have been deprecated. However, if you're working on the DOM code (front-end) and see this deprecated notice, you can use the window object to get around it.

window.atob()

For more info

2 of 4
115

TLDR: These functions btoa and atob are deprecated for Node JS. If you are coding for the web browser you just need to prepend the window to get rid of this deprecation mark.

to encode :

window.btoa('test') 

result: dGVzdA==

to decode

window.atob('dGVzdA==')

result: test


Otherwise, you could install buffer with "yarn add buffer" or "npm i buffer" to run on browser. The buffer module's API is identical to node's Buffer API.

Here is a React sample using javascript module to browser, but it can run on any modern javascript frontend app that uses webpack or parcel or even vanilla javascript with script src:

//this will run on browser    
import React from "react";
import { Buffer } from 'buffer';
export default function App() {

  const encodeBase64 = (data) => {
    return Buffer.from(data).toString('base64');
  }
  const decodeBase64 = (data) => {
    return Buffer.from(data, 'base64').toString('ascii');
  }

  return <div>
    {'encoded test to base64 = ' + encodeBase64('test')}<br />
    {'decoded dGVzdA== to ascII = ' + decodeBase64('dGVzdA==')}
  </div>;
}

The above react hook will result:

encoded test to base64 = dGVzdA==
decoded dGVzdA== to ascII = test

btoa(): accepts a string where each character represents an 8bit byte. If you pass a string containing characters that cannot be represented in 8 bits, it will probably break. Probably that's why btoa is deprecated.

atob(): returns a string where each character represents an 8-bit byte.

If you are using nodejs just replace atob and btoa with Buffer. Here is the official documentation Buffers in nodejs:

//With NodeJS

export const encodeBase64 = (data) => {
    return Buffer.from(data).toString('base64');
}
export const decodeBase64 = (data) => {
    return Buffer.from(data, 'base64').toString('ascii');
}
🌐
Medium
medium.com › @lvhaitao0301 › introduction-of-javascripts-btoa-function-223f6e82a359
Introduction of JavaScript’s btoa function | by HAITAO LYU | Medium
February 13, 2025 - The btoa function in JavaScript is used to encode a binary string (where each character is treated as a byte) into a Base64 string. It works with ASCII or Latin1 characters (0x00–0xFF).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › WorkerGlobalScope › btoa
WorkerGlobalScope: btoa() method - Web APIs | MDN
const encodedData = self.btoa("Hello, world"); // encode a string const decodedData = self.atob(encodedData); // decode the string · Base64, by design, expects binary data as its input. In terms of JavaScript strings, this means strings in which the code point of each character occupies only one byte.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › atob
Window: atob() method - Web APIs | MDN
The atob() method of the Window interface decodes a string of data which has been encoded using Base64 encoding. You can use the Window.btoa() method to encode and transmit data which may otherwise cause communication problems, then transmit it and use the atob() method to decode the data again.
🌐
Reddit
reddit.com › r/learnjavascript › what does **b** and **a** in `btoa()` mean?
r/learnjavascript on Reddit: What does **b** and **a** in `btoa()` mean?
August 10, 2019 -

There are two functions called btoa() and atob() which will respectively encode strings to base64 and decode them from it.

But what does a/b stand for? I tried to remember them as btoa, will convert base to something and atob will convert something to base and worked fine for me until now. I was just wondering what actually are them?

🌐
LinkedIn
linkedin.com › pulse › exploring-base64-encoding-decoding-functions-btoa-atob-falamarzi
Exploring the Base64 Encoding and Decoding Functions in JavaScript: btoa() and atob()
July 13, 2023 - Introduction: In JavaScript, the ... decoding. The btoa() function allows you to create a Base64-encoded ASCII string from a binary string, treating each character as a byte of binary data....
🌐
Broadcom Community
community.broadcom.com › vmware-cloud-foundation › discussion › using-btoa-to-base64-encode-ascii-string-javascript
Using btoa to base64 encode ascii string (javascript) | VMware Aria Automation Orchestrator
Hello,I am trying to use the btoa function in vCO 8.1 to encode a string. I see the btoa function listed as available in the editor, but I'm not actually sure h
🌐
Fuse Community
forums.fusetools.com › feature suggestions
How to use "btoa" (and "atob") in Javascript? - Feature Suggestions - Fuse Community
September 26, 2015 - Ive tried to base64 encode a string in javascript by using “btoa(mystring)”. “StackTrace: ReferenceError: btoa is not defined” Am I missing a require?
🌐
Medium
hyunbinseo.medium.com › base64-in-node-js-and-browser-c7fba48ae033
Base64 in Node.js and browser. Choosing between Buffer and atob (btoa) | by Hyunbin | Medium
March 5, 2022 - JavaScript · Typescript · Jwt · Hyunbin · 1 min read · ·Mar 5, 2022 · -- Listen · Share · Use atob() and btoa() in browsers and Cloudflare Workers · Use Buffer.from(string[, encoding]) in Node.js · Using window.atob() instead since atob() is marked as deprecated in a Node.js Typescript project.
🌐
Endojs
docs.endojs.org › functions › _endo_base64.btoa.html
btoa | Endo
btoa · btoa(stringToEncode: string): string · stringToEncode: string · the binary string to encode · an ASCII string containing the base64 representation of stringToEncode · Defined in btoa.js:7 · Member Visibility · Protected · Inherited · External · Theme ·
🌐
GitHub
github.com › gopherjs › gopherjs › issues › 580
Using `btoa` and `atob` for faster Base64 encoding and decoding · Issue #580 · gopherjs/gopherjs
January 28, 2017 - Modern browsers support the atob and btoa functions for Base64 encoding and decoding respectively. I just threw together some benchmarks that demonstrate this could be an area for improved performance with GopherJS, which show that the n...
Author: gopherjs
🌐
n8n
community.n8n.io › questions
Function - how to do btoa javascript function - Questions - n8n Community
March 12, 2021 - Hi, for an HTTP request, I need to use btoa to base64 encode the token. As btoa is part of the window class which does not seem to be available - how can I do this instead? Btw, a little “bug” here: If I create an expression for a HTTP Request variable, btoa works in the preview (I guess ...
🌐
Medium
medium.com › @tuteja_lovish › exploring-atob-and-btoa-in-javascript-a-guide-to-base64-encoding-and-decoding-ffd98197c42d
Exploring atob and btoa in JavaScript: A Guide to Base64 Encoding and Decoding | by CodeTalks | Medium
December 4, 2024 - btoa: Converts binary data to a Base64-encoded string. atob: Decodes a Base64-encoded string back into binary data. These functions are native to JavaScript and are part of the Window object in browsers.
🌐
Attacomsian
attacomsian.com › blog › javascript-base64-encode-decode
Base64 encoding and decoding in JavaScript
October 9, 2022 - There are two built-in functions in JavaScript for encoding and decoding raw binary data into Base64 strings. The btoa() function (stands for binary-to-ASCII) is used to create a Base64 encoded ASCII string from the binary data.
🌐
GitHub
github.com › formulahendry › vscode-code-runner › issues › 505
atob and btoa are not defined · Issue #505 · formulahendry/vscode-code-runner
July 19, 2019 - VS Code Version: 1.36.1 OS Version: Windows 10 Pro 10.0.17134 Code Runner Version: 0.9.11 Describe the bug atob and btoa are not defined. To Reproduce Steps to reproduce the behavior: Create a small JS snippet btoa("test") Execute the sn...
Author: formulahendry