Base64 в браузере
// Кодирование
const encoded = btoa('Hello World');
// "SGVsbG8gV29ybGQ="
// Декодирование
const decoded = atob('SGVsbG8gV29ybGQ=');
// "Hello World"Base64 в Node.js
const encoded = Buffer.from('Hello World').toString('base64');
const decoded = Buffer.from('SGVsbG8gV29ybGQ=', 'base64').toString('utf8');Часто задаваемые вопросы
Почему btoa() не работает со спецсимволами?
btoa() принимает только Latin-1. Для Unicode используйте TextEncoder или encodeURIComponent.