base64 encode node js

Buffers in Node.js can be used to work with binary data, and can be encoded into base64 using the Buffer class's toString method. To encode a string to base64, you first create a new Buffer from the string, then use the toString method with 'base64' encoding.