Provides helper functions to detect connected USB printers and define network printer configurations. Use this for POS or retail applications requiring local hardware integration.
// Source: https://github.com/vijayg10/openvyapar | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import USB from 'escpos-usb';
export interface PrinterInfo {
type: 'usb' | 'network';
name: string;
address?: string;
}
export function discoverUSBPrinters(): PrinterInfo[] {
try {
const devices = USB.findPrinter();
return devices.map((d: any, i: number) => ({
type: 'usb' as const,
name: `USB Printer ${i + 1}`,
}));
} catch {
return [];
}
}
export function getNetworkPrinter(ip: string, port = 9100): PrinterInfo {
return {
type: 'network',
name: `Network Printer (${ip}:${port})`,
address: `${ip}:${port}`,
};
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key