-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (28 loc) · 1008 Bytes
/
app.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
const express = require('express')
const app = express()
const QRCode = require('qrcode')
app.get('/create-qr', function (req, res) {
var content = req.query.content
if (typeof content !== 'undefined' && ! content) {
res.send("You must pass in a content query parameter of type AlphaNumeric, Numeric, Byte or Kanji to be encoded.")
}
var errorCorrectionLevel = req.query.errorCorrectionLevel || 'L'
var margin = req.query.margin || 4
var dark = req.query.dark || '#000000ff'
var light = req.query.light || '#ffffffff'
var options = {
errorCorrectionLevel: errorCorrectionLevel,
margin: margin,
color: {
dark: dark,
light: light // Transparent background
}
}
QRCode.toDataURL(content, options, function (err, url) {
if (err) res.status(400).send('Bad Request: '+err);
res.send(url)
})
})
app.listen(3000, function () {
console.log('Node QR Generator listening on port 3000!')
})