Skip to content

Node.js SDK

Terminal window
npm install vaartix

Works with Node.js 18 and later, in ESM and CommonJS, with TypeScript types included.

import { Vaartix } from 'vaartix';
// Reads VAARTIX_API_KEY from the environment if no key is passed.
const vaartix = new Vaartix(process.env.VAARTIX_API_KEY);

Every method resolves to { data, error }. Exactly one is set:

const { data, error } = await vaartix.emails.send({ ... });
if (error) {
// error.type: 'validation_error', 'rate_limited', 'network_error', ...
// error.statusCode: HTTP status, or null for network errors
console.error(error.type, error.message);
return;
}
console.log(data.id);
// Send one email (optionally idempotent)
await vaartix.emails.send(
{ from: '[email protected]', to: '[email protected]', subject: 'Receipt', html: '<p>...</p>' },
{ idempotencyKey: 'order-1042-receipt' },
);
// Schedule, then cancel
const { data } = await vaartix.emails.send({ ...email, scheduledAt: '2026-11-01T09:00:00+05:30' });
await vaartix.emails.cancel(data!.id);
// Up to 100 at once
await vaartix.batch.send([email1, email2]);
// Read (full-access key)
await vaartix.emails.get('em_7hq2kv9xr4m1c8d3');
await vaartix.emails.list({ limit: 20 });
new Vaartix(apiKey, {
baseUrl: 'https://api.vaartix.com', // default
fetch: customFetch, // e.g. for testing
});

React Email support (passing react: <MyEmail />) is planned.