How to integrate EmailTemplate in Node.js
Node 18+ ships with fetch, so you do not need any SDK: the API is consumed directly. This guide builds a small client, an Express endpoint that renders, and a decoupled send queue, with the API key only on the server.
How do I call the EmailTemplate API from Node.js step by step?
-
Create the fetch client
One function per operation keeps the code readable. The API key is read from process.env and the timeout prevents hangs.
ts// src/lib/email-template.ts const BASE = process.env.EMAIL_TEMPLATE_API_URL ?? 'https://api.emailtemplate.theboomer.dev/api/v1' const KEY = process.env.EMAIL_TEMPLATE_API_KEY as string async function api(path: string, init: RequestInit = {}) { const res = await fetch(BASE + path, { ...init, headers: { 'Content-Type': 'application/json', 'x-api-key': KEY, ...(init.headers ?? {}) } }) if (!res.ok) throw new Error('EmailTemplate ' + res.status + ': ' + (await res.text())) return res.json() } export const createTemplate = (name: string, subject: string, html: string) => api('/templates', { method: 'POST', body: JSON.stringify({ name, subject, blocks: [], html }) }) export const renderTemplate = (id: string, variables: Record<string, string>) => api('/templates/' + id + '/render', { method: 'POST', body: JSON.stringify({ variables }) }) export const createVersion = (id: string, html: string, message: string) => api('/templates/' + id + '/versions', { method: 'POST', body: JSON.stringify({ html, message }) }) -
Render a template
The render returns the final HTML, the text version and the variables used. It is the single source of truth for the email content.
tsimport { renderTemplate } from './lib/email-template' const { html, text, subject, usedVariables } = await renderTemplate( '64f8a1b2c3d4e5f6a7b8c9d1', { 'user.name': 'Ana', 'order.id': 'A-1024' } ) console.log(subject, usedVariables.length) -
Version a change
Each save creates a version with a message, branch and parent. You can compare versions and roll back from the API or the dashboard.
tsimport { createVersion } from './lib/email-template' const version = await createVersion( '64f8a1b2c3d4e5f6a7b8c9d1', '<h1>New header</h1><p>{{ user.name }}</p>', 'Update the welcome header' ) console.log(version.version) -
Express endpoint that sends
The controller renders with EmailTemplate and sends with your ESP. The key never leaves the server.
ts// src/routes/orders.ts import { Router } from 'express' import { renderTemplate } from '../lib/email-template' const router = Router() router.post('/orders/:id/notify', async (req, res, next) => { try { const { html, subject } = await renderTemplate( process.env.ORDER_TEMPLATE_ID as string, { 'user.name': req.body.userName, 'order.id': req.params.id } ) // await resend.emails.send({ to: req.body.email, subject, html }) res.json({ ok: true }) } catch (err) { next(err) } }) export default router -
Decouple sending with a queue
Rendering is fast, but the ESP can fail. Enqueue the send and retry with backoff; the user gets an immediate response.
ts// src/workers/mail.ts (pattern with BullMQ) import { Queue, Worker } from 'bullmq' import { renderTemplate } from '../lib/email-template' export const mailQueue = new Queue('mail', { connection }) new Worker('mail', async (job) => { const { templateId, variables, to } = job.data const { html, subject } = await renderTemplate(templateId, variables) // send with Resend/Klaviyo and handle retries here }, { connection }) -
Use the MCP server with agents
If an LLM agent must create or version templates, connect the MCP server over SSE. It exposes 13 tools for templates, versions and AI generation.
bashclaude mcp add emailtemplate --transport sse https://mcp.emailtemplate.theboomer.dev/sse
| Item | Free | Pro | Team | Enterprise |
|---|---|---|---|---|
| Monthly price (EUR, VAT excluded) | €0 | €19 | €59 | €149 |
| Renders per month | 500 | 25,000 | 100,000 | 500,000 |
| Concurrent templates | 3 | 25 | Unlimited | Unlimited |
| Users | 1 | 2 | 10 | 25 |
| AI credits per month | 50 | 500 | 2,000 | 10,000 |
| AI operation cost | generate: 10 credits · suggest: 5 credits. Charged to the credit wallet (they do not consume renders) and the same on every plan. Packs: 500 credits / €9, 2,000 / €29, 5,000 / €69, 10,000 / €119. | |||
| Stack provider export | format=klaviyo returns Liquid HTML, format=mailchimp returns JSON with *|VARIABLE|* merge tags and format=resend returns a React Email component as JSX (text/javascript). | |||
Subscription prices in USD/month; credit packs are charged in EUR. Product-published data, not estimates.
Frequently asked questions
Do I need to install an EmailTemplate SDK?
No. Node 18+ has fetch and the API is REST. The client in this guide covers create, render, versions and export.
Where should the API key live?
In process.env on the server. Never in the client bundle or in the repository.
How do I version a change from Node?
Call POST /api/v1/templates/:id/versions with the new html and a message. Each version is immutable and can be compared or rolled back.