nam-simpleserver
v1.3.0
Published
Tiny API-key-protected HTTP server: write a string, read it back.
Readme
simple_server
Tiny API-key-protected HTTP server: write a string, read it back. Zero dependencies (Node stdlib only).
Run
API_KEY=your-secret npx nam-simpleserver # foreground — logs stream here, Ctrl+C to stop
API_KEY=your-secret npx nam-simpleserver -d # detached — runs under pm2 (auto-installs pm2 if missing)Starts on http://localhost:3000. Override the port: PORT=8080 npx nam-simpleserver.
API_KEY is required — without it the server exits rather than serving /write open.
Generate one with openssl rand -hex 16.
Detached (-d) management: pm2 logs nam-simpleserver, pm2 restart nam-simpleserver, pm2 stop nam-simpleserver. Run pm2 save once to survive reboots.
From a clone instead: npm start.
Endpoints
| Method | Path | Auth | What |
|--------|-----------------|------|-------------------------------|
| POST | /write | yes | Body = the string to store |
| GET | /read | yes | Returns the stored string |
| GET | /docs | no | Swagger UI |
| GET | /openapi.json | no | OpenAPI spec |
/write and /read require X-API-Key: $API_KEY; anything else gets 401. /docs is
open so the browser can load it — use its Authorize button to try the endpoints.
curl -X POST localhost:3000/write -H "X-API-Key: $API_KEY" -d 'hello'
curl localhost:3000/read -H "X-API-Key: $API_KEY" # -> helloThe string persists in data.txt (gitignored).
Test
npm test