Home Web Front-end JS Tutorial Nodejs implements a super simple method to generate QR codes

Nodejs implements a super simple method to generate QR codes

May 29, 2018 pm 04:37 PM
nodejs Generate QR code

This article mainly introduces the method of nodejs to achieve super simple generation of QR codes, and analyzes the related operation skills of nodejs based on the qr-image plug-in to generate QR codes in the form of examples. Friends in need can refer to it

The example in this article describes how nodejs implements a super simple method of generating QR codes. Share it with everyone for your reference, the details are as follows:

Use node-qrcode (https://github.com/soldair/node-qrcode) at the beginning, but you need to install it during the installation. python, and does not support python3.0 or above. When installing python2.0, you need to install other environments, so I gave up.

Finally chose a niche plug-inqr-image(https://github.com/alexeyten/qr-image)

The front page is as follows

views/index.ejs

<!DOCTYPE html>
<html>
<head>
  <title><%= title %></title>
  <link rel='stylesheet' href='/stylesheets/style.css'/>
</head>
<body>
<h1><%= title %></h1>
<img src="/create_qrcode?text=http://blog.csdn.net/fo11ower"/>
</body>
</html>
Copy after login

Backend code:

routes/index.js

var qr = require('qr-image')
router.get('/', function (req, res, next) {
  res.render('index', {title: 'Express'});
});
router.get('/create_qrcode', function (req, res, next) {
  var text = req.query.text;
  try {
    var img = qr.image(text,{size :10});
    res.writeHead(200, {'Content-Type': 'image/png'});
    img.pipe(res);
  } catch (e) {
    res.writeHead(414, {'Content-Type': 'text/html'});
    res.end('<h1>414 Request-URI Too Large</h1>');
  }
})
Copy after login

Finally Effect

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Vue.js form control operation summary

Instance of spirngmvc js passing complex json parameters to controller

JS gets url parameters, JS sends POST request method in json format

The above is the detailed content of Nodejs implements a super simple method to generate QR codes. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The difference between nodejs and tomcat The difference between nodejs and tomcat Apr 21, 2024 am 04:16 AM

The difference between nodejs and tomcat

The difference between nodejs and vuejs The difference between nodejs and vuejs Apr 21, 2024 am 04:17 AM

The difference between nodejs and vuejs

Is nodejs a backend framework? Is nodejs a backend framework? Apr 21, 2024 am 05:09 AM

Is nodejs a backend framework?

What is the difference between npm and npm.cmd files in the nodejs installation directory? What is the difference between npm and npm.cmd files in the nodejs installation directory? Apr 21, 2024 am 05:18 AM

What is the difference between npm and npm.cmd files in the nodejs installation directory?

Is there a big difference between nodejs and java? Is there a big difference between nodejs and java? Apr 21, 2024 am 06:12 AM

Is there a big difference between nodejs and java?

Is nodejs a back-end development language? Is nodejs a back-end development language? Apr 21, 2024 am 05:09 AM

Is nodejs a back-end development language?

Which one to choose between nodejs and java? Which one to choose between nodejs and java? Apr 21, 2024 am 04:40 AM

Which one to choose between nodejs and java?

What are the global variables in nodejs What are the global variables in nodejs Apr 21, 2024 am 04:54 AM

What are the global variables in nodejs

See all articles