Your API Is Public the Moment It Ships
The moment your Node.js API goes live, automated scanners start probing it — testing default credentials, fuzzing endpoints, attempting injection attacks. This is not hypothetical; it happens within minutes of a new IP appearing on the public internet. Most Node.js APIs ship with the framework defaults, which are optimised for development convenience, not production security.
This guide covers the practical hardening steps every production Node.js API needs — from JWT implementation that does not have the common pitfalls, to Redis-backed rate limiting that survives restarts, to secrets management that does not leak credentials through your git history. All code is production-ready and can be dropped into an Express application.
Step 1 — Input Validation with Zod
Input validation is your first line of defence. Every piece of data entering your API from the outside world must be validated against an explicit schema before your application logic touches it. Zod is the best TypeScript-first validation library for this — it validates at runtime and infers TypeScript types from the same schema definition.