# A Prompt That Writes Express Endpoints I Actually Ship

> The constraint list that turns a toy endpoint into a production one.

- **Author:** [Camila Silva (@camila_silva)](https://www.promptabide.com/camila_silva)
- **Published:** 2026-06-17
- **Updated:** 2026-08-22
- **Tags:** `backend`, `express`, `typescript`, `api`
- **Views:** 8011
- **Likes:** 571

## Prompt

```
Generated endpoints are usually 80% there and missing exactly the 20% that matters in production. This constraint block closes the gap:

"Write an Express + TypeScript endpoint.

Endpoint: [method] [path]
Purpose: [one sentence]

Non-negotiables:
- Validate the body with express-validator; return 422 with field-level errors
- Auth via the existing authMiddleware; 401 if absent, 403 if the role is wrong
- Wrap DB work in a transaction and roll back on any throw
- No secrets or IDs in log lines
- Return the shared ResponseHelper envelope, never res.json directly
- Paginate any list response, default 20, max 100
- Handle the unique-constraint violation explicitly, not as a 500"

The last two are the ones I used to fix by hand on every single generated endpoint. Putting them in the prompt cut my review time roughly in half.
```

## Output

*Produced by Claude · claude-sonnet-4.*

```
router.post("/orders", authMiddleware, validate(createOrderRules), async (req, res) => {
  const t = await sequelize.transaction()
  try {
    const order = await Order.create({ ...req.body, user_id: req.user.id }, { transaction: t })
    await t.commit()
    return ResponseHelper.success(res, "Order created", order)
  } catch (err) {
    await t.rollback()
    if (err instanceof UniqueConstraintError) {
      return ResponseHelper.validationError(res, "Order reference already exists")
    }
    throw err
  }
})
```

---

Canonical HTML: https://www.promptabide.com/bides/prompt-express-endpoints-camila-silva-4
Agent guide: https://www.promptabide.com/llms.txt · https://www.promptabide.com/agent-instructions.md
Sitemap: https://www.promptabide.com/sitemap.xml
