Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Express example — live code-health endpoint

A small Express API (/orders) with a genuinely real-time code-quality endpoint sitting next to it (/code-health). Every request re-runs analyse() against this app's own src/ — not a report generated once and checked in.

src/services/orderService.js deliberately includes one large, many-branched function (calculateOrderTotal) alongside small clean helpers — a shape most real services end up with eventually. Hit /code-health and you'll see it flagged for real.

Run it

cd examples/express-api
npm install   # installs express + code-multivitals via "file:../.."
npm start     # http://localhost:3300

Routes

Route What it does
GET / Lists available routes
GET /orders List orders (in-memory store)
POST /orders Create an order — runs the intentionally-complex calculateOrderTotal()
GET /code-health Live analyse() result as JSON (reportJson), 5s cache
GET /code-health/dashboard Live 4-tab HTML dashboard (reportDashboard) — open in a browser
GET /code-health/badges/:name Live SVG badge (health | mi | status), generated on the fly
curl http://localhost:3300/code-health | jq '.averageHealthScore, .errorCount'
open http://localhost:3300/code-health/dashboard   # or just paste the URL in a browser
curl http://localhost:3300/code-health/badges/health -o health.svg

The integration pattern

src/codeHealth.js is the whole pattern in ~30 lines: glob your source, call analyse(), hand the result to whichever reporter fits the route, cache with a short TTL so a burst of requests doesn't re-parse your entire source tree. Copy that file into any existing Express app and mount it:

app.use("/code-health", require("./codeHealth"));