Securing a Node.js API

7 posts · 84 min, best read in order

Validation, authentication, transport and headers: the layers that stop a public Node.js API from becoming someone else's tool.

  1. 1 Ship Safer Nodejs APIs: Validate & Sanitize (Joi vs Zod) 9 minSecure Node.js APIs: Master Input Validation & Sanitization with Zod, Joi & class-validator (Defense Against Injection & Flaws).
  2. 2 Master Input Validation & Sanitization in Node.js/Expressjs 22 minBoost Express.js security against injections through effective input sanitization. Includes step-by-step code snippets for immediate implementation.
  3. 3 JWT Auth in Node.js & Express: Access + Refresh Tokens 10 min Add JWT auth to Node.js and Express the safe way: 15-minute access tokens, rotating refresh tokens in httpOnly cookies and a logout that works.
  4. 4 Advanced Authentication Patterns in Node.js & Express.js 6 minMaster advanced Node.js/Express authentication: JWT + HttpOnly cookies, refresh token rotation, passkeys, magic links & more secure patterns with code.
  5. 5 HTTP Headers: Complete Guide to Secure & Optimize Your APIs 9 minA definitive guide to HTTP headers; from security headers that block attacks to performance headers that speed up apis; with production-ready code examples.
  6. 6 HTTPS and SSL/TLS: Securing Node.js Applications in 2025 5 minA complete guide to implementing modern HTTPS/TLS in Node.js. Learn certificates, best practices, code examples, and why plain HTTP is no longer acceptable.
  7. 7 Rate Limiting and Idempotency Keys in Node.js APIs 23 minBuild rate limiting and idempotency keys for Node.js APIs: an atomic GCRA Lua script in Redis, IETF RateLimit headers and a Postgres Idempotency-Key ledger.