几行代码搭建一个二维码服务
Opened this issue · 0 comments
manxingxing commented
const express = require('express');
const app = express();
var QRCode = require('qrcode');
app.get('/', function (req, res) {
let {data, w} = req.query;
let width = 150;
if (!data) {
res.status(400).end();
return
}
if (w) {
width = parseInt(w, 10);
}
QRCode.toFileStream(res, data, { width: width, margin: 2 })
});
app.listen(4000, () => {
console.log('listening on port 4000');
});