Send from a Node.js worker/script

Use the Publiq SDK in any Node.js script, worker or serverless function (ESM or CommonJS).

Example worker that processes a queue and sends one email per item:

import { Publiq } from 'publiq';

const publiq = new Publiq(process.env.PUBLIQ_API_KEY);

export async function processJob(job) {
  await publiq.emails.send({
    from: 'you@yourdomain.com',
    to: job.email,
    templateKey: job.template,
    variables: job.data,
  });
}

Best practices

  • Always call Publiq from the server — never expose the API key on the client.
  • Create the client instance once and reuse it across requests.
  • Prefer templateKey over inline HTML to keep content versioned.
  • Handle PubliqError (status/code); the SDK already retries transient errors with backoff.
  • Send from a verified domain — see Domains.

See also

Send from a Node.js worker/script — Publiq Docs