To read file into a base64 string in Node.js, we call the readFile method.
For instance, we write
const fs = require("fs").promises;
const contents = await fs.readFile("/path/to/file.jpg", { encoding: "base64" });
to call the readFile method to read the /path/to/file.jpg file into a base64 string by setting the encoding option to 'base64'.