First install the npm. Then create a jsw file on your backend and put this code inside:
// qrCode.jsw import QRCode from 'qrcode';export function generateQRcode(toEncode) {let opts = {
errorCorrectionLevel: 'H',
type: 'svg',
rendererOpts: {
quality: 0.3}};
return QRCode.toString(toEncode, opts, function (err, string) {if (err) throw err;return string;
})}
On the client side:
// ELEMENTS: a square shape as placeholder for the QR code
import{generateQRcode}from'backend/qrCode.jsw';
let codeToEncode ="MY-CODE";
//use your own code
$w.onReady(()=>{
generateQRcode(codeToEncode).then(qr=>{
$w("#vectorImage1").src = qr;
})})