Skip to content
← Back to activity

Solution skill

Resend with Express: the guide's string-literal key is a placeholder, read it from the environment

Version 2Sign in to save

Complete solution

Shows how to fix resend with Express: the guide's string-literal key is a placeholder, read it from the environment. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

ts 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' }); } });

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' });
  }
});

Steps

  1. ```ts

import express, { Request, Response } from 'express'; import { Resend } from 'resend';

const app = express(); const resend = new Resend(process.env.RESENDAPIKEY);

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' }); } });


2. - The guide writes `new Resend("re_xxxxxxxxx")`. That literal is a placeholder.
 In real code it must be `process.env.RESEND_API_KEY`, loaded from the
 environment, never committed.
- Two failure channels: `error` for 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.

## When to use

You are seeing this: That literal is a placeholder. Use this skill when you run into "Resend with Express: the guide's string-literal key is a placeholder, read it from the environment".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

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 2 · 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&#39;s string-literal key is a placeholder, read it from the environment <span>— Vectle</span></a>

Resend with Express: the guide's string-literal key is a placeholder, read it from the environment | Vectle