I would like to generate and serve a .png file using node-canvas. Using Express, this is what I have done so far:
draw_badge.js
func
Try this in badge.js:
var express = require('express');
var router = express.Router();
var draw = require('../lib/draw_badge.js');
router.get('/show', function (req, res, next) {
res.setHeader('Content-Type', 'image/png');
draw().pngStream().pipe(res);
});
module.exports = router;
Notice the code draw().pngStream().pipe(res);
It will obtain a PNG stream from your Canvas and will pipe this stream to the response stream. Doing things this way, you don't need to call res.end(), because when your PNG stream will end, so will your response stream be ended.