Use createInvoice to send invoice data to the hosted API and saveInvoice to save the resulting PDF locally.
Important:
- Set
"type": "module" in your package.json if using TypeScript/ESM. - Use
mode: "development" to add an EXAMPLE watermark. - For production, omit
mode or set it to "production". - Provide an
apiKey in the data object (or via a Bearer header) for account access; otherwise, it uses free access.
import easyinvoice, { type InvoiceData } from "easyinvoice";
const data: InvoiceData = {
mode: "development",
sender: {
company: "Sample Corp",
address: "123 Main Street",
zip: "78701",
city: "Austin, TX",
country: "United States",
},
client: {
company: "Client Corp",
address: "456 Oak Avenue",
zip: "75201",
city: "Dallas, TX",
country: "United States",
},
information: {
number: "2026.0001",
date: "09/11/2026",
dueDate: "09/25/2026",
},
products: [
{
quantity: 2,
description: "Consulting",
taxRate: 8.25,
price: 75,
},
],
bottomNotice: "Please pay within 14 days.",
settings: { currency: "USD", locale: "en-US", format: "Letter" },
};
const apiKey = process.env.EASYINVOICE_API_KEY;
if (apiKey) data.apiKey = apiKey;
easyinvoice
.createInvoice(data)
.then((result) => easyinvoice.saveInvoice(result, "invoice.pdf"))
.catch((error) => console.error(error));