Validate a Peppol invoice in Node.js in 5 minutes
A step-by-step tutorial: validate a UBL / Peppol BIS / EN 16931 invoice in Node.js against XSD and Schematron using the free peppol-validator npm package — no Java required.
Peppol and EN 16931 invoices are strict XML: a file that "looks fine" can still fail the rules a tax authority or the Peppol network enforces. In this tutorial we validate one in Node.js in about five minutes, using the free, open-source peppol-validator package — no Java or JVM involved.
What you need
- Node.js 18 or newer.
- An invoice XML file (UBL Invoice or CreditNote) — call it invoice.xml.
- About five minutes.
Step 1 — Install the package
npm install peppol-validatorStep 2 — Check the structure (XSD)
First, validate the XML against the UBL 2.1 schema. The OASIS schemas are bundled, so this needs zero configuration — the root element is detected automatically.
import { readFileSync } from 'node:fs';
import { validateXsd } from 'peppol-validator';
const xml = readFileSync('./invoice.xml', 'utf-8');
const result = validateXsd(xml);
console.log(result.root, result.valid); // e.g. "Invoice" true
if (!result.valid) console.error(result.errors);result.valid tells you if the structure is correct; result.errors lists any problems with line numbers. This catches malformed documents instantly.
Step 3 — Add the business rules (Schematron)
XSD only checks the shape. The real EN 16931 and Peppol rules — totals must reconcile, VAT categories must be consistent, mandatory fields must be present — live in Schematron. Those rule sets are not bundled (they belong to OpenPEPPOL and the other bodies), so you download the official .sch once and compile it with the included tool:
# Download the official Peppol BIS Schematron (.sch) from docs.peppol.eu, then:
npx peppol-validator-compile PEPPOL-EN16931-UBL.sch ./artefacts/PEPPOL-EN16931-UBL.sef.jsonNow run XSD and the business rules together in a single call:
import { readFileSync } from 'node:fs';
import { validate, resolveSef } from 'peppol-validator';
const xml = readFileSync('./invoice.xml', 'utf-8');
const sef = resolveSef('peppol-bis-3', './artefacts');
const report = await validate(xml, { sef });
console.log('valid:', report.valid);
for (const e of report.schematron?.errors ?? []) {
console.log(e.id + ': ' + e.message);
}Step 4 — Read the result
- report.valid — overall pass/fail (XSD and Schematron combined).
- report.xsd.errors — structural problems.
- report.schematron.errors — business-rule failures, each with a rule ID (e.g. BR-CO-10) and a human-readable message.
- report.schematron.warnings — non-fatal issues you may still want to fix.
That is it
In a handful of lines you have both structural and business-rule validation for Peppol BIS, EN 16931 or XRechnung — running anywhere Node runs, with no Java. Point it at a different compiled rule set to validate other profiles or the procurement documents.
Get peppol-validator on npmWhere MyInvoice fits in
peppol-validator checks documents. If you also need to generate them — turning CSV, Excel, UBL, EDIFACT or your ERP data into a compliant EN 16931 invoice — that is exactly what MyInvoice does: convert, validate and return a send-ready document through one API.