How to Generate QR Code in Node JS?

By Hardik Savani August 31, 2021 Category : Node JS

In this tutorial we will go over the demonstration of how to generate qr code in node js. This article goes in detailed on node.js generate qr code. we will help you to give example of generate qr code in node js. i would like to show you node qr code generator.

In this example we will use qrcode npm package for generate qr code. we will create json data object and create qr code for that.

so let's follow simple step to send mail with node js.

Step 1: Create Node App

run bellow command and create node app.

mkdir my-app

cd my-app

npm init

Step 2: Install qrcode

run bellow command and install qrcode npm package.

npm install qrcode -S

Step 3: Create server.js file

server.js

const qr = require('qrcode');

let data = {

id: 1,

name: "User",

email: "user@gmail.com"

};

let strData = JSON.stringify(data)

qr.toString(strData, {type:'terminal'},

function (err, code) {

if(err) return console.log("error occurred")

console.log(code)

});

qr.toDataURL(strData, function (err, code) {

if(err) return console.log("error occurred")

console.log(code)

})

now you can simply run by following command:

node server.js

Output:

i hope it can help you...

Tags :
Shares