@mehdiislight/zebra-zpl
v1.0.0
Published
A lightweight client for sending ZPL to network-connected Zebra label printers via TCP/IP.
Readme
zebra-zpl
A lightweight TypeScript client for sending ZPL commands to network-connected Zebra label printers via TCP/IP.
Zero dependencies — uses Node.js built-in net module.
Installation
npm install zebra-zplUsage
import { ZebraClient } from 'zebra-zpl';
const client = new ZebraClient('10.0.0.50');
await client.connect();
await client.send('^XA^FO50,50^ADN,36,20^FDHello World^FS^XZ');
client.disconnect();Factory method
const client = ZebraClient.printer('10.0.0.50');
await client.connect();
await client.send(zpl);
client.disconnect();Custom port
The default port is 9100. You can override it:
const client = new ZebraClient('10.0.0.50', 6101);Error handling
Connection and send failures throw a CommunicationError:
import { ZebraClient, CommunicationError } from 'zebra-zpl';
const client = new ZebraClient('10.0.0.50');
try {
await client.connect();
await client.send('^XA^FDTest^FS^XZ');
} catch (err) {
if (err instanceof CommunicationError) {
console.error(err.message); // Human-readable error
console.error(err.code); // Socket error code (e.g. "ECONNREFUSED")
}
} finally {
client.disconnect();
}API
new ZebraClient(host: string, port?: number)
Creates a client instance. Does not connect automatically.
ZebraClient.printer(host: string, port?: number): ZebraClient
Static factory — same as calling new ZebraClient(...).
client.connect(): Promise<void>
Opens a TCP connection to the printer.
client.send(zpl: string): Promise<void>
Sends a ZPL string to the printer. Must be connected first.
client.disconnect(): void
Closes the connection and cleans up the socket.
Requirements
- Node.js 14+
- Printer must be reachable on the network (same network or routed)
- Default printer port: 9100
License
MIT
