Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos

Home » Nodejs » How to Generate QR Code in Node JS Application

How to Generate QR Code in Node JS Application

How to Generate QR Code in Node JS Application

Posted on October 20, 2021February 17, 2022 By XpertPhp

In this article, we will explain to you how to generate QR code in node js application. They are usually used to encode a URL so that someone can simply scan the code and visit a site.

A QR code (Quick Response Code) is a machine-readable optical identifier that can include information about the item to which the code is attached.

Table of Contents

  • Node Js Application Setup
  • Install NPM Package
  • Run Node js Application

Node Js Application Setup

First, we will open the command prompt and create the application in our directory. for this, you can follow the below command.

1
2
3
mkdir my_node_app
cd my_node_app
npm init

Install NPM Package

After the done setup node js application, we will install the express and qrcode npm package. so you can see the following npm command.

1
2
npm install express --save
npm install qrcode --save

server.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var express=require('express');
var app = express();
var QRCode = require('qrcode');
 
 
app.get('/',function(req,res){
// Creating the data
let data = {
name:"test",
age:27,
email:"[email protected]"
}
// Converting the data into String format
let stringdata = JSON.stringify(data);
// Print the QR code to terminal
QRCode.toString(stringdata,{type:'terminal'},function (err, QRcode) {
if(err){
return console.log("error occurred");
}else{
// Printing the generated code
console.log(QRcode);
}
});
  
// Converting the data into base64
QRCode.toDataURL(stringdata, function (err, code) {
if(err){
return console.log("error occurred");
}else{
// Printing the code
console.log(code);
}
})
});
 
app.listen(3000,function(){
     console.log("Express Started on Port 3000");
});

Run Node js Application

we will run the node js application using the below command. so you can follow the below command.

1
node server.js

Now you can run the example using the below Url in the browser.

1
http://localhost:3000

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • Node JS Axios HTTP DELETE Request Example
  • Node js convert image to base64 Example
  • node js routes in separate file using express
  • Node JS Axios HTTP GET Request Example
  • Node JS Http Request with Headers Example
Nodejs

Post navigation

Previous Post: Node js Session Management Using Express Session
Next Post: How to Render HTML File in Node JS Express

Latest Posts

  • Laravel Check If Foreach is Empty Example
  • Laravel Check Array Empty in Blade
  • PHP Datatables CRUD Example
  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com