node-thermal-printer-js 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/app.js +11 -8
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Public npm package for sending ESC/POS print jobs to a PSF588 printer over BLE or classic Bluetooth COM port.
|
|
4
4
|
|
|
5
|
+
## Requirements (Read First)
|
|
6
|
+
|
|
7
|
+
- Node.js is required for all usage.
|
|
8
|
+
- BLE mode requires Python 3.11+ with `bleak` installed (this package uses a Python BLE bridge).
|
|
9
|
+
- COM mode works with Node.js only, but your printer must already be paired as a COM port in your OS.
|
|
10
|
+
|
|
11
|
+
## Quick Config (.env)
|
|
12
|
+
|
|
13
|
+
All runtime settings can be changed from `.env` (transport, COM port, BLE name/address/UUID, timeouts) so you do not need to edit code files.
|
|
14
|
+
|
|
5
15
|
## Install
|
|
6
16
|
|
|
7
17
|
```bash
|
package/app.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
1
2
|
import { spawn } from "node:child_process";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
import path from "node:path";
|
|
@@ -57,22 +58,24 @@ const runPythonProcess = ({ cmd, cmdArgs, scriptArgs }) =>
|
|
|
57
58
|
});
|
|
58
59
|
|
|
59
60
|
const printViaComPort = async (data, options = {}) => {
|
|
60
|
-
const portPath = options.portPath || process.env.PRINTER_COM_PORT
|
|
61
|
+
const portPath = options.portPath || process.env.PRINTER_COM_PORT;
|
|
61
62
|
const baudRate = options.baudRate || 9600;
|
|
62
63
|
|
|
63
64
|
// Dynamically import `serialport` only when COM transport is requested.
|
|
64
|
-
let
|
|
65
|
+
let SerialPortCtor;
|
|
65
66
|
try {
|
|
66
|
-
SerialPortModule = await import("serialport");
|
|
67
|
+
const SerialPortModule = await import("serialport");
|
|
68
|
+
SerialPortCtor = SerialPortModule.SerialPort || SerialPortModule.default;
|
|
69
|
+
|
|
70
|
+
if (!SerialPortCtor) {
|
|
71
|
+
throw new Error("SerialPort constructor not found in module exports");
|
|
72
|
+
}
|
|
67
73
|
} catch (e) {
|
|
68
74
|
return Promise.reject(
|
|
69
75
|
new Error(`serialport module not available: ${e.message}`),
|
|
70
76
|
);
|
|
71
77
|
}
|
|
72
78
|
|
|
73
|
-
const SerialPortCtor =
|
|
74
|
-
SerialPortModule.default || SerialPortModule.SerialPort || SerialPortModule;
|
|
75
|
-
|
|
76
79
|
const port = new SerialPortCtor({
|
|
77
80
|
path: portPath,
|
|
78
81
|
baudRate,
|
|
@@ -110,7 +113,7 @@ const printViaBleBridge = (data, options = {}) => {
|
|
|
110
113
|
"--data-b64",
|
|
111
114
|
payload,
|
|
112
115
|
"--name",
|
|
113
|
-
options.bleName || process.env.PRINTER_BLE_NAME
|
|
116
|
+
options.bleName || process.env.PRINTER_BLE_NAME,
|
|
114
117
|
];
|
|
115
118
|
|
|
116
119
|
if (options.bleAddress || process.env.PRINTER_BLE_ADDRESS) {
|
|
@@ -187,7 +190,7 @@ const printViaBleBridge = (data, options = {}) => {
|
|
|
187
190
|
// Preferable on Windows: pair the PSF588 printer in OS Bluetooth settings
|
|
188
191
|
// and note the outgoing COM port (e.g. COM5). Then call `printToPSF588(data, { portPath: 'COM5' })`.
|
|
189
192
|
export const printData = (data, options = {}) => {
|
|
190
|
-
const transport = options.transport || process.env.PRINTER_TRANSPORT
|
|
193
|
+
const transport = options.transport || process.env.PRINTER_TRANSPORT;
|
|
191
194
|
|
|
192
195
|
if (transport === "ble") {
|
|
193
196
|
return printViaBleBridge(data, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-thermal-printer-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "ESC/POS printer helper for PSF588 Bluetooth and COM printing.",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"exports": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"dotenv": "^16.6.1",
|
|
34
35
|
"serialport": "^13.0.0"
|
|
35
36
|
}
|
|
36
37
|
}
|