StructOCR Node.js SDK
Add passport and document OCR to your Node.js backend without manually encoding files or maintaining REST request code.
Install the SDK
Install or upgrade the official structocr package from npm.
npm install structocrPassport OCR quickstart
Store the API key in STRUCTOCR_API_KEY, keep it on the server, and pass a supported local file to the SDK.
const StructOCR = require("structocr");
const apiKey = process.env.STRUCTOCR_API_KEY;
if (!apiKey) throw new Error("STRUCTOCR_API_KEY is not configured");
const client = new StructOCR(apiKey);
async function main() {
const result = await client.scanPassport("./passport.jpg");
if (result.success) {
const passport = result.data;
console.log(passport.passport_number);
console.log(passport.given_names, passport.surname);
} else {
console.error(result.error);
}
}
main().catch(console.error);For the complete request and response schema, see the Passport OCR API reference.
The SDK converts paths or in-memory data to Base64 locally and sends JSON with an img string. If you call the REST API directly, send either that JSON or a multipart/form-data upload with one file in file or img; file paths and URLs are not accepted.
Supported OCR methods
| Document type | SDK method | Credits | Demo |
|---|---|---|---|
| Passport scanPassport() | scanPassport() | 2 | Try it |
| Driver License scanDriverLicense() | scanDriverLicense() | 2 | Try it |
| Driver License PDF417 scanDriverLicensePdf417() | scanDriverLicensePdf417() | 2 | Try it |
| National ID scanNationalId() | scanNationalId() | 2 | Try it |
| VIN scanVin() | scanVin() | 1 | Try it |
| License Plate scanLicensePlate() | scanLicensePlate() | 1 | Try it |
| Vehicle Registration scanVehicleRegistration() | scanVehicleRegistration() | 2 | Try it |
| Invoice scanInvoice() | scanInvoice() | 3 | Try it |
| Receipt scanReceipt() | scanReceipt() | 1 | Try it |
| Container scanContainer() | scanContainer() | 1 | Try it |
| Weighbridge Ticket scanWeighbridgeTicket() | scanWeighbridgeTicket() | 2 | Try it |
| ATM Cassette scanAtmCassette() | scanAtmCassette() | 1 | |
| HIN scanHin() | scanHin() | 1 | Try it |
| Account balance getAccountBalance() | getAccountBalance() | — |
Credits are charged per successful request. Try it opens a demo that needs no account: scan a sample image or your own file in the browser.
Package registries are the source of truth for the latest published version and release notes.
Runtime
A supported Node.js server runtime
Input
Local JPG, PNG, WebP, or PDF path; or Buffer/Uint8Array
Output
Structured result with success, data, and error fields
Authentication and errors
- Read the API key from a server-side environment variable.
- Check the returned
successvalue before usingdata. - Handle invalid input, insufficient credits, and temporary service failures in your application.
- Use the API reference for HTTP status codes and detailed error layouts.
Ready to make your first SDK call?
Create an account, receive 200 free credits, and test up to 100 two-credit document scans.
Get your API key