In Node.js è relativamente semplice codificare un'immagine in Base64.
La soluzione è la seguente:
'use strict';
const encodeImg = (src) => {
let imgPath = __dirname + '/' + src;
let buff = fs.readFileSync(imgPath);
let base64data = buff.toString('base64');
return base64data;
};
module.exports = encodeImg;