title: how to add logo in the middle of the qr code using nodejs
body: <p>I am trying to create a logo and try to add a logo in the middle of the qr code and i am able to generate the qr code but unable to get the qr code with logo on the middle i have tried this code but unable to get the result getting this error</p>
  <pre><code>Error: You need to specify a canvas element
  </code></pre>
  <p>and i am using this library <a href="https://github.com/soldair/node-qrcode" rel="nofollow noreferrer">https://github.com/soldair/node-qrcode</a></p>
  <p>and here is the tried code</p>
  <pre><code>const QRCode = require(&quot;qrcode&quot;);
  const getQRcodeImage = async () =&gt; {
    try {
      let canvas = await QRCode.toCanvas(`my sample text`);
  
      //adding a log at center
      const imgDim = { width: 30, height: 30 }; //logo dimention
      var context = canvas.getContext(&quot;2d&quot;);
      var imageObj = new Image();
      imageObj.src = &quot;./Capture.png&quot;;
      imageObj.onload = function () {
        context.drawImage(
          imageObj,
          canvas.width / 2 - imgDim.width / 2,
          canvas.height / 2 - imgDim.height / 2,
          imgDim.width,
          imgDim.height
        );
      };
      return canvas;
    } catch (e) {
      console.error(e);
      return &quot;&quot;;
    }
  };
  getQRcodeImage();
  </code></pre>