Working with npm packages

Hi there,

I’m trying to use some npm packages, but I can’t figure out how use them. I want to create a pdf document with user input and create a QR code. These have nothing to do with each other, I need them separately (so no qr code inside the pdf). I’ve tried about 10 different packages now for both the pdf and the qr code but none seem to work, I always get a similar error message in the lines of “Cannot find module…”. So obviously I’m doing something wrong …

I’ve tried already;

  • Changing var qr = require ( ‘qr-image’ ); to import qr from ‘qr-image’ ;
  • reading this article about how to work with npm packages, but honestly that wasn’t helpful at all.
  • I’ve also read about all the nmp related forum posts out there, but still was unable to make them work.
  • install the zlib npm

For example I’ve added this example code in the front-end code: (which gave the error message above)

var qr = require('qr-image');
var qr_svg = qr.image('I love QR!', { type: 'svg' });
var svg_string = qr.imageSync('I love QR!', { type: 'svg' });

Any help or tips would be immensely appreciated! Thanks :slight_smile:

Hello, we have a live example with a QR code generator that you can follow to see how to create one of these.