Node
Language
Invoice Parsing in Node.js — Receipt & Invoice Extraction for JavaScript Apps
One POST request. Clean JSON back. Works in Express, Next.js, or any Node.js environment.
Trusted by developers worldwide to automate document workflows.
✓ Free DocuParseAPI account✓ Node 18+✓ Server runtime
The guide
1
No install needed for Node 18+
Node.js 18 has fetch built in. For older versions only:
npm install node-fetch form-data
2
Set your API key as an environment variable
Never put the key in client-side code:
export DOCUPARSE_API_KEY="dex_your_key_here"
3
Send the file using FormData
Read the file buffer, create a Blob, append to FormData, POST to the extract endpoint:
const fs = require("fs");
const path = require("path");
async function parseInvoice(filePath) {
const fileBuffer = fs.readFileSync(filePath);
const blob = new Blob([fileBuffer]);
const form = new FormData();
form.append("file", blob, path.basename(filePath));
const response = await fetch("https://docuparseapi.com/api/v1/extract", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.DOCUPARSE_API_KEY}` },
body: form,
});
const data = await response.json();
if (!data.success) throw new Error(`[${data.error.code}]`);
return data;
}Need your API key first?
20 free documents/month — no credit card
4
Read the JSON response
Access fields directly — no post-processing needed:
const invoice = await parseInvoice('invoice.pdf');
console.log(invoice.merchant); // 'Acme Corp'
console.log(invoice.total); // '1320.00'
console.log(invoice.currency); // 'USD'
console.log(invoice.line_items); // array of items5
Add a server-side proxy for browser apps
Never call the DocuParseAPI from browser JavaScript — your key would be exposed. Use a Next.js API route to proxy the request:
// app/api/invoices/upload/route.ts
import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
const formData = await request.formData();
const file = formData.get("file") as File;
const upstream = new FormData();
upstream.append("file", file);
const response = await fetch("https://docuparseapi.com/api/v1/extract", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.DOCUPARSE_API_KEY}` },
body: upstream,
});
return NextResponse.json(await response.json());
}Full working example
javascript
const fs = require("fs");
const path = require("path");
async function parseInvoice(filePath) {
const fileBuffer = fs.readFileSync(filePath);
const blob = new Blob([fileBuffer]);
const form = new FormData();
form.append("file", blob, path.basename(filePath));
const response = await fetch("https://docuparseapi.com/api/v1/extract", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.DOCUPARSE_API_KEY}` },
body: form,
});
const data = await response.json();
if (!data.success) throw new Error(`[${data.error.code}] ${data.error.message}`);
return data;
}
const invoice = await parseInvoice("invoice.pdf");
console.log(`${invoice.merchant}: ${invoice.currency} ${invoice.total}`);
for (const item of invoice.line_items || []) {
console.log(` ${item.description}: ${item.quantity} x ${item.unit_price}`);
}What gets extracted
Common errors and fixes
Ready to start?
20 documents free every month. No credit card. Set up in 5 minutes.
Get Your Free API Key