I try to make a web app to print on LQ-310 Printer using express and QZ-Tray. However, I cannot execute the printing process as expected, it only triggered to print if users hit the endpoint, if I put the QZ-Tray functions inside another function. I have tried to create a dedicated file for it and execute it using bash/shell script if users trigger the endpoint like this:
const printInvoice = (req, res) => {
fs.writeFile(`src/invoice/invoice.json`, JSON.stringify(req.body), (err) => {
if (err) throw err;
});
// shell script to run qz-tray
const shell = require('shelljs');
shell.echo('Running qz-tray');
shell.exec('bash src/invoice/qz-tray.sh');
fs.readFile(`src/invoice/invoice.json`, (err, data) => {
if (err) throw err;
res.json(JSON.parse(data));
});
}
However, my terminal return no result, not even error message.
I also have set out to just do it inside one function on route, but found no result.