node-thermal-printer-js 1.0.2 → 1.0.3

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.
Files changed (3) hide show
  1. package/README.md +10 -0
  2. package/app.js +4 -3
  3. 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,7 +58,7 @@ 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 || "COM5";
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.
@@ -110,7 +111,7 @@ const printViaBleBridge = (data, options = {}) => {
110
111
  "--data-b64",
111
112
  payload,
112
113
  "--name",
113
- options.bleName || process.env.PRINTER_BLE_NAME || "PSF588",
114
+ options.bleName || process.env.PRINTER_BLE_NAME,
114
115
  ];
115
116
 
116
117
  if (options.bleAddress || process.env.PRINTER_BLE_ADDRESS) {
@@ -187,7 +188,7 @@ const printViaBleBridge = (data, options = {}) => {
187
188
  // Preferable on Windows: pair the PSF588 printer in OS Bluetooth settings
188
189
  // and note the outgoing COM port (e.g. COM5). Then call `printToPSF588(data, { portPath: 'COM5' })`.
189
190
  export const printData = (data, options = {}) => {
190
- const transport = options.transport || process.env.PRINTER_TRANSPORT || "ble";
191
+ const transport = options.transport || process.env.PRINTER_TRANSPORT;
191
192
 
192
193
  if (transport === "ble") {
193
194
  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.2",
3
+ "version": "1.0.3",
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
  }