Print in Node.js


Good night, I'm new here, I hope not to commit any infractions and be of help, I tell them that I'm dealing with the impression in Node.js, the need is to create a software in node.js and run it directly on the computer where I will have connected 3 printers (we will call them a, b and c), according to the requirement will print in 'a' or in 'b' or in 'c', the problem is that I have tried with a module called escpos, where it tells me that I must use a program named Zadig to print on windows, well I do it that way but it generates an error that the printer can not find, I do not know if I should put something in the program folder or something like that, the code I have is:

const escpos = require('escpos');

const device  = new escpos.USB();
const printer = new escpos.Printer(device); => {
    .text('Hello World')
    .close(() => {

this is the error that generates also use one that was advised here, called node-printer, but also tells me that you can not find the printer

this is the code:

var Printer = require('node-printer');
var options = {
    media: 'Custom.200x600mm',
    n: 3

// Get available printers list

// Create a new Pinter from available devices
var printer = new Printer('TM-T88V');

// Print from a buffer, file path or text
var fileBuffer = fs.readFileSync('/path/to/file.ext');
var jobFromBuffer = printer.printBuffer(fileBuffer);

var filePath = 'package.json';
var jobFromFile = printer.printFile(filePath);

var text = 'Print text directly, when needed: e.g. barcode printers'
var jobFromText = printer.printText(text);

// Cancel a job

// Listen events from job
jobFromBuffer.once('sent', function() {
    jobFromBuffer.on('completed', function() {
        console.log('Job ' + jobFromBuffer.identifier + 'has been printed');

and this is the error

Thank you very much in advance for your collaboration, many greetings

asked by Netico 15.04.2017 в 09:21

1 answer


Well I already solved it, I put the answer in case someone has the same problem.

Within the parentheses of USB( ) , when opening the device, you must put the VendorId and productId of the printer in question, and voilá .

const escpos = require('escpos');

const device  = new escpos.USB( 0x35b, 0x303 ); // Ejemplo. En MI caso.
const printer = new escpos.Printer(device);
answered by 17.04.2017 в 08:15