Home > Back-end >  how to get all attached printers name on our computer using nodeJS
how to get all attached printers name on our computer using nodeJS

Time:02-26

my scenario is... I'm making a web application for a restaurant using (NodeJS and Angular 12), and they are using thermal printers, all printers connected via USB and LAN. I need a solution - how I can get the list of all connected printers and print receipts on all printers without a preview dialog box..!!!

currently, I'm not able to list all connected printers list, and print receipts on them

please help me to find a proper solution

CodePudding user response:

There was a node-printermodule but I guess it was abandoned, the last most recent module for that is zuzel-printer, but the last update is from 6 years ago. Let's hope it fits your needs

Link: zuzel-printer https://www.npmjs.com/package/zuzel-printer

CodePudding user response:

const { exec } = require('child_process');
exec('wmic printer list brief', (err, stdout, stderr) => {
if (err) {
    // node couldn't execute the command
    return;
}
// list of printers with brief details
console.log(stdout);
// the *entire* stdout and stderr (buffered)
stdout = stdout.split("  ");
var printers = [];
j = 0;
stdout = stdout.filter(item => item);
for (i = 0; i < stdout.length; i  ) {
    if (stdout[i] == " \r\r\n" || stdout[i] == "\r\r\n") {
        printers[j] = stdout[i   1];
        j  ;
    }
}
// list of only printers name
console.log(printers);
console.log(stderr);
});
  • Related