惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
WordPress大学
WordPress大学
罗磊的独立博客
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security
S
SegmentFault 最新的问题
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
腾讯CDC
Engineering at Meta
Engineering at Meta
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
D
DataBreaches.Net
雷峰网
雷峰网
GbyAI
GbyAI
宝玉的分享
宝玉的分享

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
5 Production Mistakes That Changed How I Build Express APIs
Lolo · 2026-06-18 · via DEV Community

Lolo

I stopped thinking APIs break because of “complex code”.

They break because of boring things you didn’t take seriously.

Here are 5 lessons from production:


1. Validate early or suffer later

I used to validate inside the logic.

Then weird bugs started appearing far from the source.

Now I just kill bad requests immediately:

if (!req.body.email || typeof req.body.email !== "string") {
  return res.status(400).json({ error: "Valid email is required" });
}

No validation inside business logic. Ever.


2. Your errors are part of your API contract

A generic 500 is useless in production.

Be explicit:

return res.status(401).json({ error: "Invalid API key" });

return res.status(402).json({ error: "Insufficient credits" });

If your error needs explanation in Slack, your API message failed.


3. Middleware order can break everything silently

I once debugged “broken auth” for hours.

It was just middleware order.

app.use(cors());           // must go first
app.use(express.json());
app.use(authMiddleware);
app.use("/api", routes);

Move one line and everything changes.


4. Logging should be boring, not noisy

I’ve tried both extremes.

Both were wrong.

What actually helps in production:

console.log(`${req.method} ${req.path} -> ${res.statusCode}`);

And for real debugging:

console.error({
  requestId,
  error: err.message,
  stack: err.stack
});

Everything else becomes noise at 3AM.


5. Rate limiting is not “later”

I learned this after watching an endpoint get hammered and cost real money.

import rateLimit from "express-rate-limit";

const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 60,
  message: { error: "Too many requests" }
});

app.use(limiter);

If your API has no limits, it doesn’t have protection. It has hope.


Final thought

Most API failures don’t come from complex engineering.

They come from ignoring the basics because “it’ll be fine”.

It won’t.

Production doesn’t care.