Node.js SDK
Send email with SvelteKit
Use Parcel Wing from SvelteKit server actions while keeping API keys server-only.
Install the SDK
The official SDK is published as @parcelwing/node.
Terminal
npm install @parcelwing/node
Server action
Put sending logic in +page.server.ts so the API key never ships to the browser.
src/routes/invite/+page.server.ts
import { fail, type Actions } from "@sveltejs/kit";import { ParcelWing, ParcelWingError } from "@parcelwing/node";const parcelWing = new ParcelWing({ apiKey: process.env.PARCEL_WING_API_KEY! });export const actions = {sendWelcome: async ({ request }) => {const formData = await request.formData();try {const [message] = await parcelWing.emails.send({from: "Acme <[email protected]>",to: String(formData.get("email") ?? ""),template_alias: "welcome_email",template_params: { first_name: String(formData.get("firstName") ?? "friend") },});return { id: message?.id };} catch (error) {if (error instanceof ParcelWingError) {return fail(error.status, { code: error.code, requestId: error.requestId });}return fail(500, { error: "Unexpected error" });}},} satisfies Actions;
Production notes
- Keep
PARCEL_WING_API_KEYin server-only environment variables. - Validate recipient addresses and public form input before sending.
- Use saved templates for onboarding, invites, receipts, and other repeatable lifecycle email.