IntegrationsNode.js
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.

Get Your Free API KeyView API Docs
Free DocuParseAPI accountNode 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
Get Free API Key →
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 items
5
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

merchantThe vendor or store name
totalThe final charged amount including tax
subtotalThe pre-tax amount
taxThe tax amount charged
dateInvoice or transaction date (ISO 8601)
due_datePayment due date, or null if not present
invoice_idInvoice number or receipt ID from the document
currencyISO 4217 currency code (USD, EUR, GBP, etc.)
payment_methodCard type, cash, or other payment method
line_itemsArray of items with description, quantity, unit_price, total

Common errors and fixes

MISSING_API_KEYAuthorization header missingAdd header: Authorization: Bearer YOUR_KEY
INVALID_API_KEYKey not recognisedCheck key in dashboard — regenerate if needed
LIMIT_EXCEEDEDMonthly document limit reachedUpgrade at docuparseapi.com/pricing
UNSUPPORTED_FILE_TYPEFile format not supportedUse PDF, JPG, or PNG only
FILE_TOO_LARGE_AUTHENTICATEDFile exceeds 10 MBCompress the file before sending
EXTRACTION_FAILEDDocument could not be parsedTry a cleaner scan or different file

Ready to start?

20 documents free every month. No credit card. Set up in 5 minutes.

Get Your Free API Key