AakashRajni
AakashRajni

Reputation: 382

How to convert a string or data into QR Code in Node Js

I need to convert user data into a QR Code and show it in the web browser what is the best way to generate QR Code in node js and show it in user browser

Upvotes: 4

Views: 13474

Answers (2)

Kush07
Kush07

Reputation: 1

You can use this url in image tag like this ->

Example of app.js or index.js file

var QRCode = require('qrcode');
app.get('/', function (req, res) {
 QRCode.toDataURL('I am a pony!', function (err, url) {
  console.log(url)
  res.render('index', {qr: url});
  });
});

In your template: (i am using ejs as my template engine)

<img src="<%= qr %>">

after this you will get qrcode image instead of qrcode data. i hope this would help you

Upvotes: -1

Sparw
Sparw

Reputation: 2743

I think you should look at qrcode library

This is an exemple of basic usage :

var QRCode = require('qrcode')

QRCode.toDataURL('I am a pony!', function (err, url) {
  console.log(url)
});

Hope it helps.

Upvotes: 6

Related Questions