TypeScript library for ESC/POS thermal printer communication
npm install @luisvillafania/escposA TypeScript library for communicating with ESC/POS thermal printers. This library provides an easy-to-use API for generating print commands for receipt printers, POS printers, and other thermal printing devices.
- ✨ Written in TypeScript with full type definitions
- 🎯 Simple, chainable API
- 📦 Zero dependencies
- 🔧 Support for common ESC/POS commands
- 💪 Works with Node.js 14+
``bash`
npm install escpos
`typescript
import { EscPosPrinter } from 'escpos';
const printer = new EscPosPrinter();
// Create a simple receipt
printer
.initialize()
.align('center')
.bold(true)
.size(2, 2)
.text('MY STORE')
.feed(1)
.bold(false)
.size(1, 1)
.text('123 Main Street')
.feed(2)
.align('left')
.text('Item 1.................. $10.00')
.feed(1)
.text('Item 2.................. $15.00')
.feed(1)
.text('--------------------------------')
.feed(1)
.align('right')
.bold(true)
.text('TOTAL: $25.00')
.feed(3)
.cut();
// Get the buffer to send to printer
const buffer = printer.getBuffer();
// Send to printer (example with a writable stream)
await printer.print(printerStream);
`
`javascript
const { EscPosPrinter } = require('escpos');
const printer = new EscPosPrinter();
printer
.initialize()
.text('Hello World')
.feed(2)
.cut();
const buffer = printer.getBuffer();
`
The main printer class with a chainable API.
#### Methods
- initialize() - Initialize the printertext(content: string)
- - Print textfeed(lines?: number)
- - Feed paper (default: 1 line)align(alignment: 'left' | 'center' | 'right')
- - Set text alignmentbold(enabled?: boolean)
- - Set bold text (default: true)size(width?: number, height?: number)
- - Set text size (1-8, default: 1)cut(partial?: boolean)
- - Cut paper (default: full cut)getBuffer()
- - Get the complete print bufferclear()
- - Clear the bufferprint(stream?: NodeJS.WritableStream)
- - Print to stream or get buffer
Low-level ESC/POS command generators if you need more control.
Check the examples/ directory for more usage examples:
`bash`
node examples/basic.js
`bash`
npm run build
`bash`
npm run lint
`bash`
npm run format
1. Update version in package.jsonnpm run build
2. Build the project: npm publish`
3. Publish:
MIT
Contributions are welcome! Please feel free to submit a Pull Request.