DEVELOPERS / NODE.JS / ZPL
Print ZPL Labels From Node.js
Two ways to print labels from Node.js: raw ZPL over a TCP socket to port 9100, or the LabelInn Node SDK — print to any printer from any server, with queueing, status and templates.
const net = require('net');
const zpl = '^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ';
const socket = net.createConnection(9100, '192.168.1.50', () => socket.end(zpl));
socket.on('error', (err) => console.error('Printer unreachable:', err.message));THE PROBLEM

You need Node.js code to put a label on a thermal printer: a shipping label when an order is paid, a product label when a batch is finished. There are two ways to do it. This page shows both, with code you can paste.
01 / NODE.JS
The quick way: raw ZPL to port 9100
Zebra printers, and most printers that emulate ZPL, accept raw ZPL on TCP port 9100. If your code runs on the same network as the printer, this is all it takes:
const net = require('net');
const zpl = '^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ';
const socket = net.createConnection(9100, '192.168.1.50', () => socket.end(zpl));
socket.on('error', (err) => console.error('Printer unreachable:', err.message));02 / ZPL
Why not just open a socket?
Writing ZPL to port 9100 works on the bench. In production it leaves you with problems the printer will not solve for you:
- Your server has to reach the printer. A cloud-hosted Node.js app cannot open a socket to a printer on a warehouse LAN without a VPN or port forwarding.
- Nothing tells you it printed. Port 9100 accepts the bytes whether or not the ribbon is out or the head is open.
- Nothing queues. If the printer is off, the job is gone.
- One language per printer. ZPL works on Zebra; TSC wants TSPL, Toshiba wants TPCL.
LabelInn puts a small runtime next to the printer that connects out to the cloud. Your code calls one HTTPS API from anywhere; the job is queued, delivered in the printer's own language, and its status comes back.
npm install labelinn, one API key, and your Node.js code prints to any registered printer, anywhere. Get a key →
03 / ZEBRA
Install the SDK
npm install labelinn04 / API
Find the printer
Register the printer once in the LabelInn app on the computer it is connected to. Then list your printers to get the id:
const LabelInn = require('labelinn');
const client = new LabelInn('sk_live_...');
const printers = await client.fleet.list();
for (const p of printers) console.log(p.id, p.name, p.status);05 / NODE.JS
Print ZPL
const job = await client.print.create({
printer_id: 'prt_abc123',
payload_type: 'zpl',
payload_data: '^XA^FO50,50^A0N,40,40^FDHello from LabelInn^FS^XZ',
});
console.log(job.id, job.status);06 / ZPL
Print a designed label with data
Raw ZPL means your code owns the layout. With a template, the label is designed visually in LabelInn and your code sends only the data. Fields fill by name, and LabelInn converts the design to ZPL, TSPL or TPCL for whichever printer you choose.
const job = await client.print.create({
printer_id: 'prt_abc123',
payload_type: 'template',
design_id: 'dsg_shipping',
data: { order_id: 'ORD-9876', customer: 'Jane Doe', barcode: 'TR123456789' },
copies: 2,
});07 / ZEBRA
Print many labels in one call
Batch up to 100 jobs per request. Each job is accepted or rejected on its own, so one bad row does not sink the rest.
const result = await client.print.batch(
['A-1001', 'A-1002', 'A-1003'].map((sku) => ({
printer_id: 'prt_abc123',
payload_type: 'template',
design_id: 'dsg_product',
data: { sku },
})),
);
console.log(`${result.succeeded} of ${result.total} accepted`);08 / API
Never print the same label twice
Retries happen: a timeout, a redeploy, a queue redelivery. Send an idempotency key and a repeated call returns the original job instead of printing again.
const job = await client.print.create(
{ printer_id: 'prt_abc123', payload_type: 'template', design_id: 'dsg_shipping', data: { order_id: 'ORD-9876' } },
{ idempotencyKey: 'order-ORD-9876-label' },
);Printing through the API is part of the Pro plan, and the free trial includes it. Keys that start with sk_test_ run against a sandbox that never prints, so you can build and test before going live. See pricing.
09 / NODE.JS
Same thing, other languages
TESTED
What was run for this page
The snippets on this page were run on 17 October 2026 against a local mock of the API (the official SDK, installed from its package registry) and a local listener standing in for port 9100. They prove the request shape and the code compiles and runs; they do not prove a physical print.
Node.js 24 and labelinn 3.1.0 from npm. The SDK sent User-Agent: labelinn-node/3.1.0; idempotent calls carried X-Idempotency-Key: order-ORD-9876-label from the { idempotencyKey } option; print.batch printed 3 of 3 accepted.
| SDK fact | Value (checked 17 October 2026) |
|---|---|
| Package | labelinn 3.1.0 on npm (npm install labelinn) |
| Runtime | Node.js 18 or newer; no dependencies, it uses the built-in fetch |
| Extras | Type definitions (index.d.ts), a labelinn command-line tool, an Edge client for the LAN API with TLS pinning |
| Base URL | Pass { baseUrl } as the second constructor argument to point at a mock or a proxy |
NODE-SPECIFIC
process.exit() right after socket.write() throws labels away
// wrong: exits before the kernel buffer is flushed
socket.write(zpl);
process.exit(0);
// right: end() flushes, and its callback says when it is done
socket.end(zpl, () => process.exit(0));Measured on loopback with a 5,400,006-byte ZPL job (200,000 label fields): write() then process.exit() delivered 917,012 bytes; end() delivered all 5,400,006. A single label is a few hundred bytes and usually survives, so this bites in batch scripts that print hundreds of labels and then exit.
ERRORS
Rate limits and API errors in the SDK
const LabelInn = require('labelinn');
try {
await client.print.create({ printer_id: 'prt_abc123', payload_type: 'zpl', payload_data: '^XA^XZ' });
} catch (e) {
if (e.name === 'LabelInnRateLimitError') await sleep(e.retryAfter * 1000);
else if (e instanceof LabelInn.LabelInnError) console.error(e.status, e.code, e.message);
else throw e;
}Tested against a mock returning 429 BURST_RATE_LIMIT (printed LabelInnRateLimitError 429 BURST_RATE_LIMIT retryAfter=7) and 400 INVALID_PRINTER (a LabelInnError).
QUESTIONS / FAQ
Frequently asked questions
How do I print a ZPL label from Node.js?
On the same network, write the ZPL to the printer's TCP port 9100. From anywhere else, install the LabelInn SDK, register the printer once, and call print.create with payload_type "zpl" and the printer id.
Can my cloud-hosted Node.js app print to a printer in a warehouse?
Yes. The LabelInn runtime next to the printer connects out to LabelInn, so your server calls an HTTPS API and never needs network access to the printer itself.
Does it only work with Zebra printers?
No. Raw ZPL needs a ZPL printer, but templates are converted to the printer's own language, including TSPL for TSC and TPCL for Toshiba.
How do I avoid printing duplicates when a request is retried?
Send an idempotency key with the job. Repeating the call with the same key returns the original job instead of printing again.
Can I print from JavaScript in the browser?
Browsers cannot open raw TCP sockets. Either call your own backend, which uses the SDK, or call the LabelInn runtime's local API on your network; see printing from a web app.
Why did my Node.js script print only part of the batch?
Calling process.exit() right after socket.write() can discard data still in the buffer. Use socket.end(data, callback) and exit from the callback; on a 5.4 MB job the difference was 917,012 bytes against all of them.
Does the LabelInn Node SDK need any dependency?
No. It uses the fetch built into Node.js 18 and later.
KEEP GOING
Related
NEXT STEP / LABELINN
Print from Node.js without touching a printer driver
Get an API key, register a printer, and send your first label in minutes. · Official SDK · ZPL or visual templates · Queue, status and retries handled