Trust is earned, not given

A different perspective

2024-02-17 · Projects

GoShop in Node.js: 40 endpoints, idempotency and a degraded mode

NodeJs (the GoShop sample) is the Node.js sibling of the Go shopping service: an Express application with a 40-endpoint HTTP surface, PostgreSQL, Redis caching, JWT auth with TOTP 2FA, and an email outbox worker. Stack: Node 20+, Express 4, pg, ioredis, jsonwebtoken, otplib, bcryptjs.

The route map

GroupRoutes
healthzGET /healthz
customers + auth13
products5
cart6
orders4
payments6
shipping5

Boot order in src/server.js reads like a checklist: connect the pool → run embedded migrations → attach Redis (falling back to a no-op Null cache in degraded mode when Redis is unreachable) → token manager → services → seed demo data → mount the router → listen with graceful shutdown.

Three disciplines the sample hammers

What the email outbox teaches

Instead of sending email inline (slow, and what if SMTP is down?), requests append to an outbox table and src/email/worker.js drains it separately. Your checkout stays fast, and email becomes retryable work instead of a failure mode.

Repository: github.com/bobhuang1/NodeJs — the per-endpoint breakdown lives in ROUTES.md.