Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

Build a POS receipt printer in Node.js

Disclosure: I build Receiptful, the printing API used in this tutorial. The Node and Express parts apply whatever you print with. You have orders coming into your point of sale, and you want each one to print on the thermal printer at the counter. This is a complete walkthrough of a small Node service that does exactly that. By the end you will have an endpoint you can POST an order to and watch…

In this tutorial, a Node.js service is created to print orders on a thermal printer at a point of sale. The printer is identified by a printer ID, and an API key is required to authenticate requests. The service uses TypeScript but can also be written in plain JavaScript.

To begin, the shape of an order must be defined, which includes the item name, quantity, unit price in cents, and the order ID, placed date, and list of line items. Using cents for monetary values helps avoid floating-point rounding issues.

Next, the order is rendered as HTML. Receiptful converts this HTML into ESC/POS commands specific to the printer, allowing for a custom layout using familiar HTML tags. Helper functions are provided to format monetary values.

Finally, the rendered HTML is sent to the printer using a POST request to the printer's job endpoint. The request includes headers for authentication and content type. Upon successful completion, the job ID is returned, indicating that the receipt is being printed.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

My First Time Putting an App on AWS (A Beginner's Story)

Today I did something I've wanted to do for a while — I took an app running on my own laptop and put it "live" on the internet using AWS.

  • AWS provides virtual servers to run apps without owning physical hardware.
  • EC2 service offers managed virtual computers for application hosting.
  • App was successfully accessed via browser using instance's public DNS.

More from Sunday 16 August →