0

In an api point I want to save a qrcode as png in local file system then in the same api I want to get that saved image and use it to make a pdf file. But in the function the pdf making function is running before saving the file in the file system. How can I force/ensure the file saved and the move to next line.

console.log("this line 1");

QRCode.toDataURL(`https://www.mindschoolbd.com/verifycertificate/?certificateID=${genId}`, function (err, url) {
    let base64String = url;
    let base64Image = base64String.split(";base64,").pop();
      
    let writeBuffer = new Buffer.from(base64Image, "base64");
    fs.writeFileSync(
        `./userCertificates/qrCodes/${genId}.png`,
         writeBuffer
    );
    console.log("this line 2");
})
console.log("this line 3");

In my case I am getting output like this:

this line 1
this line 3
this line 2

but I want it to be

this line 1
this line 2
this line 3
Mark Girgis
  • 125
  • 1
  • 9
Manas S. Roy
  • 303
  • 1
  • 10

0 Answers0