Base64 no Navegador
// Codificar
const encoded = btoa('Hello World');
// "SGVsbG8gV29ybGQ="
// Decodificar
const decoded = atob('SGVsbG8gV29ybGQ=');
// "Hello World"Base64 no Node.js
const encoded = Buffer.from('Hello World').toString('base64');
const decoded = Buffer.from('SGVsbG8gV29ybGQ=', 'base64').toString('utf8');FAQ
Por que btoa() falha com caracteres especiais?
btoa() só aceita Latin-1. Para Unicode use TextEncoder ou encodeURIComponent.