I am new to Express and I need your help.
How to save SVG on server using Express?
const qr = require('qr-image');
const fs = require('fs');
exports.qr = function (req, res) {
var code = qr.image(new Date().toString(), { type: 'svg' });
// I would like to do something like this:
fs.writeFile('qr.svg', code, (er)=> console.log(er));
// and download using express.static
res.type('svg');
code.pipe(res);
};
Currently I am returning image as a stream and it works fine.
I have an api with mongodb built on Express and I would like to store QR Codes on the server side. Api is for the application built with Xamarin managing event tickets.
QR images are going to be downloaded more than once, that's why I would like to put them on server.
Maybe better way would be to store them with SQLite locally on the client device? Or maybe I should just send json data to be parsed into SVG?
How do you think?
At the moment I am not implementing db locally.
After some time when I went back to the topic I found the solution. You need to add new action to your pipe. Simple as that:
var code = qr.image(ticket.code, { type: 'svg' });
code.pipe(fs.createWriteStream('i_love_qr.svg'));