PrintBase
  • Product
  • Pricing
  • Docs
  • Resources
PrintBase/Guides/Print from your language or framework

Print receipts from Express

An Express route can post an ESC/POS receipt when an order is created. The API key stays in the Express process, not in the static frontend.

For Express APIs that take orders for a counter printer

Overview

Express is usually the order API. After you persist the order, build the receipt bytes and POST them before you return 201 to the client. Do not block the request for the physical print; the print call itself returns when the job is queued.

ESC/POS is content_type raw. A PDF receipt is pdf. Pick one per printer. The agent will not convert HTML from res.render into a receipt.

Share the Idempotency-Key with any other worker that might also print that order, or you will get two tickets.

Create the job with POST /v1/print-jobs, an Authorization: Bearer header, printer_code, content_type pdf or raw, and exactly one of content or content_url. The free plan is 100 jobs a month on one computer.

Integration steps

  1. 01

    Create an API key on the server

    Use an API key (pb_live_…) in the process environment. Authorization is Bearer. Do not ship the key to browsers or mobile apps.

  2. 02

    Install the agent beside the printer

    Windows, macOS, or Linux. GET /v1/printers and keep the numeric code.

  3. 03

    POST /v1/print-jobs

    content_type is pdf or raw. Send exactly one of content (standard base64) or content_url.

  4. 04

    Reuse the idempotency key on retry

    A new key means a second physical print. HTTP 409 means the same key was reused with a different body.

  5. 05

    Read the job before you tell the user

    GET /v1/print-jobs/{id}. Paid plans can also receive print_job.completed and print_job.failed webhooks.

Node.js

// Express handler: ESC/POS receipt
const res = await fetch('https://api.printbase.cloud/v1/print-jobs', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.PRINTBASE_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': order.id,
  },
  body: JSON.stringify({
    printer_code: Number(process.env.PRINTER_CODE),
    content_type: 'raw',
    content: receipt.toString('base64'),
    copies: 1,
  }),
});
if (!res.ok) throw new Error(`PrintBase ${res.status}: ${await res.text()}`);
const job = await res.json();
// { id: "job_abc", status: "queued" }

Details for this setup

Do not print in middleware for every request

Only the order-create handler should print. A logging middleware that prints will burn paper.

Encoding

Build the Buffer in the code page the receipt printer expects. UTF-8 Chinese will look wrong on most ESC/POS devices.

Questions

Can the React frontend call Express, and Express call PrintBase?

Yes. That is the right split. The frontend never sees the print key.

Body parser and base64?

You send JSON out. You do not need the receipt printer to post back into Express.

Cluster mode?

Any worker can POST. The idempotency key has to be the order id, not a random uuid per worker.

How do I know the kitchen saw it?

Poll the job or use a paid webhook. Express's res.json of the create response is only queued.

Related guides

  • Print a PDF from Node.js to a printer in another place

    From Node.js, base64 a PDF and POST it to the print-jobs API. The printer is attached to a computer running the agent, not to your server.

  • Print ESC/POS receipts from Python

    Build ESC/POS bytes in Python and send them as raw. The agent does not transcode. Encode text before base64.

  • How to auto-print WooCommerce order receipts

    Print a WooCommerce order receipt from the order-status hook on your server. There is no PrintBase WooCommerce plugin; use the REST API.

  • How to auto-print kitchen tickets from your ordering site

    When your own ordering site takes an order, print an ESC/POS kitchen ticket through the API. The browser must not hold the API key.

Free plan: 100 jobs a month on one computer, no card.

Create a free accountRead the API docs
PrintBase

PrintBase connects your applications to physical printers anywhere - securely, reliably, and in real time.

Product
Receipt PrintingLabel PrintingDashboardDevicesWebhooks
Resources
DocsBlogStatusAPI ReferenceDownloadPrintBase vs PrintNodePrintNode PricingFAQ
Guides
All guidesIntegrationsPrintersCode samplesComparisonsUse casesTroubleshooting
Company
ContactSecurityPrivacy

© 2026 Aveniq Technologies OÜ. All rights reserved. PrintBase is a service of Aveniq Technologies OÜ.

PrivacyTermsRefunds