ESC/POS Printer driver for node
$ npm i escpos --save
$ yarn add escpos
if you use usb as an adapter :
libudevto build libusb.
sudo apt-get install build-essential libudev-dev.
Otherwise you will get
LIBUSB_ERROR_NOT_SUPPORTED when attempting to open devices.
const escpos = ;// Select the adapter based on your printer typeconst device = ;// const device = new escpos.Network('localhost');// const device = new escpos.Serial('/dev/usb/lp0');const printer = device;device;
./examplesfor more examples.
You can choose your adapter type as USB, Serial, Network, or Console.
const usbDevice = 0x01 0xff;
vid(Vendor Id) and pid (Product Id) can be checked with the
lsusb command or
const serialDeviceOnWindows = 'COM10';const serialDeviceOnLinux = '/dev/usb/lp0'bandRate: 14400stopBit: 2;
Check the serialport package documentation for more options.
const networkDevice = 'localhost' 3000;
The default port number is 9100.
const debugDevice = ;
Claims the current device USB (or other device type), if the printer is already in use by other process this will fail.
By default, the USB adapter will set the first printer found .
Triggers the callback function when done.
Closes the current device and releases its USB interface.
const usbDevice = ;const usbPrinter = usbDevice;const serialDevice = '/dev/usb/lp0';const serialPrinter = serialDevice;const networkDevice = 'localhost';const networkPrinter = networkDevice;
Escpos inherits its methods to the printers. the following methods are defined:
Prints raw text. Raises TextError exception.
For the encode type, see the iconv-lite wiki document. Escpos uses
iconv-lite for encoding.
If the type is undefined, the default type is GB18030.
Sets the encoding value globally. default type is GB18030 (Chinese)
printertext'동해물과 백두산이 마르고 닳도록';
Carrier feed and tabs.
align is a string which takes any of the following values:
Set text properties.
align set horizontal position for text, the possible values are:
font type could be A or B. Default: A
width is a numeric value, 1 is for regular size, and 2 is twice the standard size. Default: 1
height is a numeric value, 1 is for regular size and 2 is twice the standard size. Default: 1
Prints a barcode.
code is an alphanumeric code to be printed as bar code barcode_type must be one of the following type of codes:
The EAN type automatically calculates the last parity bit. For the EAN13 type, the length of the string is limited to 12, and EAN8 is limited to 7. (#57)
width is a numeric value in the range between (1,255) Default: 64 height is a numeric value in the range between (2,6) Default: 3 position is where to place the code around the bars, could be one of the following values:
font is one of the 2 type of fonts, values could be:
Raises BarcodeTypeError, BarcodeSizeError, BarcodeCodeError exceptions.
mode set a full or partial cut. Default: full Partial cut is not implemented in all printers.
*** Don't foget this, because cut will flush buffer to printer ***
Sends a pulse to the cash drawer in the specified pin.
pin is a numeric value which defines the pin to be used to send the pulse, it could be 2 or 5. Raises `CashDrawerError()``
Copyright (c) 2015 lsong
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.