Tutorial técnico

Integrar Verifactu en Node.js

Tutorial paso a paso para integrar la API de Verifactu en tu aplicación Node.js.

Instalar SDK

npm install @verifactu/node

Ejemplo completo

import { VeriFactu } from '@verifactu/node';

const client = new VeriFactu('sk_test_xxx');

async function crearFactura() {
  const invoice = await client.invoices.create({
    emitter: { 
      nif: 'B12345678', 
      name: 'Tu Empresa SL' 
    },
    receiver: { 
      nif: '12345678A', 
      name: 'Cliente Example SL' 
    },
    lines: [
      { description: 'Desarrollo web', amount: 1000, vat: 21 }
    ]
  });

  console.log('Factura creada:', invoice.id);
  console.log('QR Code:', invoice.qrCode);
}

crearFactura();

Configurar API Key

Obtén tu API key en el dashboard:

  • Regístrate en VeriFactu.dev
  • Ve a Settings → API Keys
  • Copia tu key (empieza por sk_test_ para pruebas)

Errores comunes

Error: NIF inválido

El NIF debe ser válido (8 dígitos + letra para personas físicas, letra + 8 dígitos para empresas).