Skip to content

Node.js

  1. Install the SDK.

    Terminal window
    npm install @spacepost/node
  2. Export your API key.

    Terminal window
    export SPACEPOST_API_KEY="sp_live_YOUR_API_KEY"
  3. Send an email.

    send.ts
    import { SpacePost } from "@spacepost/node";
    const spacepost = new SpacePost(); // reads SPACEPOST_API_KEY
    const { data, error } = await spacepost.emails.send({
    from: "Acme <hello@acme.com>",
    to: ["user@example.com"],
    subject: "Welcome to Acme",
    html: "<h1>Welcome</h1><p>Glad to have you.</p>",
    text: "Welcome. Glad to have you.",
    tags: [{ name: "category", value: "welcome" }],
    });
    if (error) {
    console.error(error.statusCode, error.name, error.message);
    process.exit(1);
    }
    console.log("Email id:", data.id);

    Run it with node send.ts (Node 22.6+ strips types) or npx tsx send.ts.

The SDK never throws on API errors: check error on every call. It uses the global fetch, so it works on Node 18+.

See the full Node.js SDK reference.