Express + Socket.IO service for storing session metadata (devices & messages) with MongoDB persistence and broadcasting real‑time updates.
- REST endpoints for creating/deleting sessions, listing & upserting devices, and posting messages
- WebSocket (Socket.IO) support for real‑time device/message broadcasts
- MongoDB back‑end for durable session storage
- TypeScript codebase with full typings
- Node.js 18+ & npm
- MongoDB instance (local, Docker, or remote Atlas)
| Name | Default | Description |
|---|---|---|
MONGO_URI | mongodb://localhost:27017/session-api | MongoDB connection string |
PORT | 2000 | HTTP & WebSocket listen port |
HOST | 0.0.0.0 | Host to bind |
CORS_ORIGIN | * | Allowed CORS origin (e.g. https://app.example.com) |
You can override these in your shell, in a .env file, or via Docker Compose.
git clone https://github.com/clip-fish/session-api.git
cd session-api
npm install
# if you have Mongo running locally:export MONGO_URI="mongodb://localhost:27017/session-api"
npm run devYour API will be up on http://localhost:2000.
npm run build # compiles TS → ./dist
npm start # runs node dist/index.jsA docker-compose.yml is included. From the repo root:
docker compose up --buildThis will launch:
- mongo – MongoDB (data in a named volume)
- api – this service, listening on port 2000
| Command | Description |
|---|---|
npm run dev | Start TS compiler with hot‑reload (ts-node-dev) |
npm run build | Transpile TypeScript to JavaScript (tsc) |
npm start | Run the compiled server (node dist/index.js) |
npm test | (no tests yet) |
POST /session → create/ensure session
DELETE /session/:sessionId → delete a session
POST /session/:sessionId/device → upsert a device
GET /session/:sessionId/devices → list devices
POST /session/:sessionId/message → add a message
GET /session/:sessionId/messages → list messages
All payloads and responses use JSON. WebSocket events are:
deviceUpdates– emits array of devicesmessageUpdates– emits array of messages
MIT © Clip Fish