I am trying to generate a route that I can use to generate a barcode based on the orderId that its passed in, however, the jsbarcode is not rendering.
This is my route code
let express = require('express');
let router = express.Router();
let url = require('url');
let JsBarcode = require('jsbarcode');
let Canvas = require('canvas')
router.get('/:orderId', function(req, res, next) {
res.send( req.param('orderId'));
var canvas = new Canvas();
JsBarcode(canvas, "Hello"); //I want to eventually pass the orderID here so that it can generate the barcode based on that.
});
module.exports = router;
The end goal is to be able to use this route to generate an image with a bardcode with the order number passed in from the route.
First, you need to get your orderId. To do that, you have to use
req.params.orderId
.Second, when you call
res.send
, it ends your call, so you can't process anything you want to send in response.Third, I don't know exactly how you want to use the canvas and jsBarcode libraries but put the orderId where you need it.
The right way to code it could be: