rocketprint
v0.1.0
Published
Node.js SDK for the RocketPrint API — driverless remote printing.
Maintainers
Readme
rocketprint
Node.js SDK for the RocketPrint API — driverless remote printing. Zero dependencies (Node 18+).
Use this SDK in your backend or worker, where your API key stays private.
npm install rocketprintSave this example as print.mjs (or use the same import in TypeScript):
import RocketPrint from 'rocketprint';
const rp = new RocketPrint(process.env.ROCKETPRINT_API_KEY);
// Find your printer (registered automatically by RocketPrint Station)
const printers = await rp.printers.list();
const zebra = printers.find((p) => p.status === 'online');
if (!zebra) throw new Error('No online printer found');
// Print a ZPL shipping label
const job = await rp.printJobs.create({
printerId: zebra.id,
contentType: 'raw_base64',
content: Buffer.from('^XA^FO50,50^A0N,40,40^FDHello^FS^XZ').toString('base64'),
title: 'Order #1042 label',
}, { idempotencyKey: 'order-1042-shipping-label' });
// Retrying identical input with the same key returns this job instead of
// printing a second copy. Reusing the key for different input returns 409.
// Wait for a terminal outcome. "completed" means the OS queue accepted the job.
const done = await rp.printJobs.waitFor(job.id);
console.log(done.status); // completed, failed, canceled, expired, or unknown
// Read a stable USB scale measurement from any connected station
const scales = await rp.scales.list();
if (scales.length) {
const reading = await rp.scales.waitForReading(scales[0].id);
console.log(reading.massGrams); // canonical grams
console.log(reading.displayValue, reading.unit); // exactly what the scale displayed
}CommonJS is also supported: const RocketPrint = require('rocketprint').
TypeScript projects using CommonJS can use
import RocketPrint = require('rocketprint'). Types ship with the package;
there is no separate @types package to install.
For backend workers, set a request timeout and bounded retries. Create requests are retried only when they carry an idempotency key:
const rp = new RocketPrint(process.env.ROCKETPRINT_API_KEY, {
timeoutMs: 10_000,
maxRetries: 2,
});
const controller = new AbortController();
await rp.printers.list({ signal: controller.signal });If the printer's agent is offline, jobs queue server-side and dispatch automatically when it reconnects.
API
rp.printJobs.create(params, { idempotencyKey, signal, timeoutMs, retries })/.list(query, opts)/.get(id, opts)/.cancel(id, opts)/.waitFor(id, opts)rp.printers.list()/.get(id)rp.scales.list()/.get(id)/.waitForReading(id, opts)
Full REST reference: API docs and OpenAPI schema.
Queue deadlines and printer settings
printJobs.create() accepts expiresInSeconds (10–86400; default 3600).
Offline jobs expire instead of printing unexpectedly days later. Only pending
jobs can be canceled. waitFor() also stops for expired and unknown.
An unknown result means the Station could not confirm the spooler outcome;
check the physical printer before creating another job.
Jobs inherit the printer defaults saved in Setup & print. Override with
options: { copies, paperSize, color, duplex, landscape }. Copies must be 1–100;
paper size is A4, Letter, Legal, or 4x6. RAW jobs accept copies only;
encode other settings in ZPL/EPL or the printer language. Unsupported options
are rejected. A completed job means the OS print queue accepted it, not proof
that paper physically emerged.
