Node.js SDK
Types, retries, paging and webhook verification for Node.js.
The @yousendit/node package wraps the API with types, retries (with an Idempotency-Key, so a retry never sends twice), cancellation through signal, paging (listAll) and webhook verification. It has no dependencies, works with import and require, and needs Node 18 or later.
Install
npm install @yousendit/nodeSend with the SDK
import { YouSendIt } from "@yousendit/node";
const ysi = new YouSendIt(process.env.YOUSENDIT_API_KEY);
const { id } = await ysi.emails.send({
from: "Acme <hello@acme.com>",
to: "sam@example.com",
subject: "Your receipt",
html: "<p>Thanks for your order!</p>",
tags: [{ name: "category", value: "receipt" }],
});
// Or a transactional template made in the app, filled in with your values:
await ysi.emails.send({ from: "Acme <orders@acme.com>", to: "sam@example.com", template_id: "<template id>", variables: { name: "Sam" } });
const email = await ysi.emails.get(id);
console.log(email.status, email.last_event);React Email
Pass a React element as react instead of html and the SDK renders it with @react-email/render (install it beside the SDK).
Options
baseUrl(orYOUSENDIT_BASE_URL),maxRetries,timeoutMs,fetch.- The key defaults to
YOUSENDIT_API_KEY. ysi.webhooks.verify(rawBody, signatureHeader, secret)checks a webhook and returns the event.