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
fromaddress.
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]>",to: "[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]>",to: "[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]>",to: "[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
Next.js
Use Parcel Wing from a Next.js application with server-side API key handling.
Remix
Use Parcel Wing from a Remix application with server-side API key handling.
Nuxt
Use Parcel Wing from a Nuxt application with server-side API key handling.
SvelteKit
Use Parcel Wing from a SvelteKit application with server-side API key handling.
RedwoodJS
Use Parcel Wing from a RedwoodJS application with server-side API key handling.
Bun
Use Parcel Wing from a Bun application with server-side API key handling.
Astro
Use Parcel Wing from a Astro application with server-side API key handling.
Railway
Use Parcel Wing from a Railway application with server-side API key handling.
Encore
Use Parcel Wing from a Encore application with server-side API key handling.
Meteor
Use Parcel Wing from a Meteor application with server-side API key handling.
Express
Use Parcel Wing from a Express application with server-side API key handling.
Fastify
Use Parcel Wing from a Fastify application with server-side API key handling.
Koa
Use Parcel Wing from a Koa application with server-side API key handling.
AdonisJS
Use Parcel Wing from a AdonisJS application with server-side API key handling.
Hono
Use Parcel Wing from a Hono application with server-side API key handling.
NestJS
Use Parcel Wing from a NestJS application with server-side API key handling.