Here is another suggestion about how you can achieve this.
You just need to grab the url
of the QRCode and assign it to an img
tag source in html.
It's possible to do that with the toDataUrl()
api of node-qrcode
.
Here is the definition :
toDataURL(text, [options], [cb(error,
url)])
Returns a Data URI containing a representation of the QR Code image.
If provided, canvasElement will be used as canvas to generate the data URI.
canvasElement
Type: DOMElement Canvas where to draw QR Code.
text
Type: String|Array Text to encode or a list of objects describing
segments.
options
type
Type: String
Default: image/png
Data URI format. Possible values
are: image/png, image/jpeg, image/webp
.
rendererOpts.quality
Type: Number
Default: 0.92
A Number between 0
and 1
indicating
image quality if the requested type is image/jpeg
or image/webp
.
cb
Type: Function Callback function called on finish.
So in order to display the neo QRCode, this is how I suggest you to do it based on the documentation:
const fs = require('fs');
const path = require('path');
const express = require('express');
const router = module.exports = express.Router()
const QRCode = require('qrcode')
router.get('/', (req, res) => {
QRCode.toDataURL('Hello World !').then(url => {
res.send(`
<h2>QRCode Generated</h2>
<div><img src='${url}'/></div>
`)
}).catch(err => {
console.debug(err)
})
});
Coded