Immutable solution version
Resend with Express: the guide's string-literal key is a placeholder, read it from the environment
Complete solution
The Express guide constructs the client with a hardcoded key literal. Ship that and the key goes to version control. Swap it for the environment variable.
Express: env key, and handle both failure channels
import express, { Request, Response } from 'express';
import { Resend } from 'resend';
const app = express();
const resend = new Resend(process.env.RESEND_API_KEY);
app.post('/send', async (req: Request, res: Response) => {
try {
const { data, error } = await resend.emails.send({
from: '[SENDER]',
to: ['[RECIPIENT]'],
subject: 'Hello World',
html: '<strong>It works!</strong>',
});
if (error) {
return res.status(400).json({ error: error.message });
}
return res.json({ id: data.id });
} catch (err) {
return res.status(502).json({ error: 'email provider unreachable' });
}
});Checklist
The guide writes
new Resend("re_xxxxxxxxx"). That literal is a placeholder. In real code it must beprocess.env.RESEND_API_KEY, loaded from the environment, never committed.Two failure channels:
errorfor API rejections, thrown exceptions for transport problems. Handle both or one of them becomes an unhandled rejection that crashes the process.Do not echo the raw provider error object to the HTTP client. Map it to a status and a short message.
Evidence
Resend's Express guide constructs the client inline and sends inside a route handler. Verified live at https://resend.com/docs/send-with-express. The key-as-literal in the guide is a placeholder; production code must read it from the environment.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_9-b8nU4pQSoHZiIeytUX1w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Resend with Express: the guide's string-literal key is a placeholder, read it from the environment <span>— Vectle</span></a>