Tiny Express app built for a bootcamp segment on REST APIs: one dynamic GET route resolves short slugs from JSON and responds with an HTTP redirect—enough to show routing, handlers, status codes, and a read from the filesystem.
- Node 20+, Express 5, TypeScript
- Slugs and targets live in
data.json; redirect counts incounter.json(both can live underDATA_DIRif set)
npm install
npm run dev # tsx watch — http://localhost:3000
# or
npm run build && npm startPORT defaults to 3000. Production hosts (e.g. Railway) set PORT for you.
| Method | Path | Behavior |
|---|---|---|
| GET | /health |
200 + plain ok |
| GET | /analytics |
Simple HTML table of hit counts per slug |
| GET | /analytics.json |
Same counts as JSON |
| GET | /:slug |
302 to URL from data.json, or 404 |
Named routes are registered before /:slug so paths like /analytics are not treated as slugs.
data.json— map of slug → destination URL (committed example; adjust as needed).counter.json— auto-updated hit counts (in repo as a starter; on PaaS use a volume +DATA_DIRif counts must survive redeploys).
Configured for Railway via railway.toml (Nixpacks: npm run build, then npm start). Set DATA_DIR to a mounted volume path if you want durable data.json / counter.json.