Simple Express + TypeScript API with three randomizers:
- Roll a die (
/roll) - Draw a playing card (
/draw) - Flip a coin (
/flip)
The home route (/) serves lightweight HTML docs describing each endpoint and examples.
- Node.js 22.18.0 (see
.nvmrc)
Using nvm:
nvm usenpm installBuilds TypeScript and starts the compiled server.
npm startServer listens on http://localhost:3000
Renders HTML documentation for the API.
Rolls a die. Faces default to 6. You can provide faces as a path parameter or query parameter.
Examples:
curl http://localhost:3000/roll
curl http://localhost:3000/roll/20
curl "http://localhost:3000/roll?faces=10"Response:
3
Draws a random playing card from a standard 52‑card set.
Optional query params for filtering:
suit: filter by suit. Acceptss|h|d|corspades|hearts|diamonds|clubs(case‑insensitive).min,max: filter by rank range. AcceptsA,2..10,J,Q,Kor numeric equivalents1,11,12,13.
Examples:
curl "http://localhost:3000/draw" # any card
curl "http://localhost:3000/draw?suit=hearts" # any heart
curl "http://localhost:3000/draw?min=8&max=K" # 8..K of any suit
curl "http://localhost:3000/draw?suit=s&min=J" # J..K..A of spadesResponse:
{
"rank": "Q",
"suit": "Hearts",
"code": "QH",
"text": "Q of Hearts",
"symbol": "Q\u2665"
}Flips a coin. Defaults to faces ["head", "tails"]. You can override face names via query params a and b.
curl http://localhost:3000/flip
curl "http://localhost:3000/flip?a=H&b=T"Response:
"head"
.
├── index.ts # App entrypoint (ESM)
├── src/
│ ├── docs.ts # HTML served at /
│ └── routers/
│ ├── index.ts # Aggregates routers
│ ├── roll.ts # /roll routes
│ ├── draw.ts # /draw routes
│ ├── flip.ts # /flip routes
│ └── types.ts # Shared types for cards
└── dist/ # Compiled JS output
npm run build– compile TypeScript todist/npm start– build then rundist/index.js
- The project uses Node ESM with
module: "NodeNext". When importing local TS files,.jsextensions are used in source so the emitted JS resolves correctly at runtime.
MIT