QR code is generated but can't be logged to the console, when stored in a variable.
I was trying to generate qrcode in a node application but when I tried logging the console, it returned undefined. Kindly help me out with this issue. I am using qrcode package.
My code:
import QRCode from "qrcode";
let qrcode;
QRCode.toDataURL("I am a pony!")
.then((url) => {
qrcode = url;
})
.catch((err) => {
console.error(err);
});
console.log(qrcode);
It logged correctly when I put console.log(url)
in the then statement.