I've been working on a web app to print on an LQ-310 Printer using express and QZ-Tray. Unfortunately, I'm facing issues with the printing process - it only prints when users hit the endpoint directly. If I try to encapsulate the QZ-Tray functions within another function, the printing doesn't trigger as expected.
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));
});
}
Despite my efforts, my terminal does not show any results or error messages.
I also attempted to streamline the process by integrating everything into one function within the route, but unfortunately, this did not yield any positive outcomes.
Note: Here is the repository where I am encountering these issues: Rusydy/print-qz