Sign inGet Started

Node.js SDK

Send email with Node.js

Install the official Parcel Wing Node.js SDK, configure a server-side API key, and send your first transactional email.

Requirements

  • Node.js 18.17 or newer.
  • A Parcel Wing API key stored as PARCEL_WING_API_KEY.
  • A verified sending domain for your from address.

Install the SDK

The official SDK is published as @parcelwing/node.

Terminal

npm install @parcelwing/node

Create a client

Initialize the SDK once on the server. Never expose your API key to browser JavaScript.

lib/parcelwing.ts

import { ParcelWing } from "@parcelwing/node";
 
export const parcelWing = new ParcelWing({
apiKey: process.env.PARCEL_WING_API_KEY!,
});

Send an email

Use parcelWing.emails.send to send one or more messages.

send.ts

const emails = await parcelWing.emails.send({
from: "Acme <[email protected]>",
subject: "Hello from Parcel Wing",
text: "It works.",
});
 
console.log(emails[0]?.id);

Templates

For product emails, prefer saved templates with typed parameters over building HTML in every endpoint.

templates.ts

await parcelWing.emails.send({
from: "Acme <[email protected]>",
template_alias: "welcome_email",
template_params: {
first_name: "Ada",
},
});

Handle errors

ParcelWingError includes status, type, code, request ID, and details.

errors.ts

import { ParcelWingError } from "@parcelwing/node";
 
try {
await parcelWing.emails.send({
from: "Acme <[email protected]>",
subject: "Hello",
text: "Hi there",
});
} catch (error) {
if (error instanceof ParcelWingError) {
console.error(error.status, error.type, error.code, error.requestId);
console.error(error.details);
}
}

Framework guides