I am trying to create a route in a nodejs app that generates a barcode from an objectId on a jade template However, as I included my route and refresh, the images is not rendering.
I've read the documentation and tried different methods but it is not rendering still.
Here is my barcode.js
var express = require('express');
var router = express.Router();
var JsBarcode = require('jsbarcode');
router.get('/', function(req, res, next) {
res.render('barcode', { title: 'Barcode' });
JsBarcode("#barcode", "Hi!");
});
module.exports = router;
Here is my jade template:
doctype html
html
head
title= title
svg#barcode
When i refresh the page, nothing shows (blank page)
What i am trying to do is get the image to render first and then eventually add more logic.
After res.render you can't have any line of code, since the page would render.
Change your barcode.js file as mentioned below
Change your barcode.jade file as mentioned below
This should give you a barcode on the page. Then you could look into sending ObjectId to the jade file for the new barcode to be generated.