How to get the list of all the printers installed/connected printers in Node.Js

Viewed 8037

I am creating a desktop application in Node.Js using Electron framework and want to get the list of all the printers installed/connected in Node.Js. I had already tried node-printer but it is not installing properly.

3 Answers
 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);
});

If you target Windows machines you could use winreg package to search the Registry for printers. All local printers can be found at

HKEY_LOCAL_MACHINE | SYSTEM | CurrentControlSet | Control | Print | Printers

, the network printers in

HKEY_LOCAL_MACHINE | SYSTEM | CurrentControlSet | Control | Print | Providers | LanMan Print Services | servers | printers

Related