excella-scanner
v1.0.0
Published
Node.js support for MagTek's Excella STX check scanner
Downloads
12
Maintainers
Readme
Excella STX Scanner support for Node.js
A Node.js library for interfacing with MagTek's Excella STX check scanner. This library provides easy-to-use methods for scanning checks and IDs, extracting MICR data, and retrieving images.
Installation
npm install --save excella-scannerConfiguration
The library supports configuration through environment variables:
MAGTEK_SCAN_URL- Scanner endpoint URL (default:/Excella?DeviceScan)MAGTEK_DEFAULT_PORT- Default scanner port (default:80)MAGTEK_REQUEST_TIMEOUT- Request timeout in milliseconds (default:30000)
Usage
Assuming your scanner is configured with IP address 192.168.1.23 and you scan the following check:
const Scanner = require('excella-scanner');
const scanner = new Scanner('192.168.1.23', 80);
const data = await scanner.readCheck(true);
/***
data {
error: false,
routing: '123456789',
account: '123456789',
number: '000001012',
frontimage: '/chkimage/FRONT100COL24_1.JPG',
backimage: '/chkimage/BACK100COL24_2.JPG',
frontimagedata: <Buffer ...>,
backimagedata: <Buffer ...>
}
***/Error Handling
try {
const data = await scanner.readCheck(true);
console.log('Check scanned successfully:', data.routing);
} catch (error) {
console.error('Failed to scan check:', error.message);
}API
Scanner Class
Constructor
new Scanner(host, port)
Creates a new instance of the Scanner object.
Parameters:
host(string, required) - IP address, hostname, or FQDN of the scannerport(number, optional) - Scanner port (default: 80 orMAGTEK_DEFAULT_PORT)
Throws: Error if host is not provided or is not a string
Methods
readCheck(includeImages = false)
Causes the scanner to read the current check and return the MICR information, potentially also returning the images.
Parameters:
includeImages(boolean, default: false) - Whether to include image data in the response
Returns: Promise that resolves to an object with the following properties:
error(boolean) - If true, the scanner cannot confirm that the information is accuraterouting(string) - The MICR routing numberaccount(string) - The MICR account numbernumber(string) - The MICR check numberfrontimage(string) - The path for the front side imagebackimage(string) - The path for the back side imagefrontimagedata(Buffer|null) - JPG data of the front side (if includeImages=true)backimagedata(Buffer|null) - JPG data of the back side (if includeImages=true)
Throws: Error if the scan operation fails
readID(includeImage = false)
Causes the scanner to read the current ID and return the image information.
Parameters:
includeImage(boolean, default: false) - Whether to include image data in the response
Returns: Promise that resolves to an object with the following properties:
frontimage(string) - The path for the front side imageimagedata(Buffer|null) - JPG data of the front side (if includeImage=true)
Throws: Error if the scan operation fails
readStatus()
Reads the current status of the scanner device.
Returns: Promise that resolves to an object with device status information including:
AccessGuide(string) - Access guide statusAutoFeeder(string) - Auto feeder statusInk(string) - Ink statusLamp1(string) - Lamp 1 statusLamp2(string) - Lamp 2 statusManualFeeder(string) - Manual feeder statusPath(string) - Path statusPrinter(string) - Printer statusState(string) - Overall device state
Throws: Error if the status read operation fails
readImage(imagePath)
Retrieves an image from the scanner by its path.
Parameters:
imagePath(string) - The path to the image on the scanner
Returns: Promise that resolves to a Buffer containing the image data
Throws: Error if the image retrieval fails
Examples
Basic Check Scanning
const scanner = new Scanner('192.168.1.23');
const data = await scanner.readCheck();
console.log(`Routing: ${data.routing}, Account: ${data.account}, Number: ${data.number}`);Check Scanning with Images
const scanner = new Scanner('192.168.1.23');
const data = await scanner.readCheck(true);
// data.frontimagedata and data.backimagedata contain Buffer objectsID Scanning
const scanner = new Scanner('192.168.1.23');
const data = await scanner.readID(true);
// data.imagedata contains the ID image as a BufferScanner Status
const scanner = new Scanner('192.168.1.23');
const status = await scanner.readStatus();
console.log(`Scanner state: ${status.State}, Ink: ${status.Ink}`);Custom Configuration
// Using environment variables
process.env.MAGTEK_REQUEST_TIMEOUT = '60000'; // 60 second timeout
const scanner = new Scanner('192.168.1.23', 8080);Error Handling
The library throws descriptive errors for various failure scenarios:
- Invalid host configuration
- Network timeouts
- XML parsing errors
- Scanner communication failures
Always wrap scanner operations in try-catch blocks for production use.
Testing
npm testGitHub Actions
This repository includes GitHub Actions workflows for automated testing and publishing:
CI Workflow
- Runs on every push and pull request
- Executes linting and tests
- Ensures code quality before merging
Publish Workflow
- Automatically publishes to npm when a new GitHub release is created
- Runs tests and linting before publishing
- Requires
NPM_TOKENsecret to be configured
Manual Publish Workflow
- Allows manual triggering of npm publishing
- Can be used to publish specific versions
- Available in the Actions tab of the repository
Setup for npm Publishing
Create an npm access token:
- Go to https://www.npmjs.com/settings/tokens
- Create a new token with "Automation" type
- Copy the token
Add the token to GitHub repository secrets:
- Go to your repository Settings → Secrets and variables → Actions
- Create a new secret named
NPM_TOKEN - Paste your npm access token
Publish your first version:
- Create a new GitHub release, or
- Use the Manual Publish workflow from the Actions tab
License
MIT
