Production-oriented Node.js API using Express, wired to the schema boilerplate at ../Boilerplate-application-schema (@applicationSchema/schemas — placeholder name).
cp .env.example .env
# Set JWT_SECRET and MongoDB values
npm install
npm run start:localdoppler run -- npm run start:localcp .env.example .env
docker compose up --buildAPI base path: /site/v1
This repo depends on your schema package via a local file: path:
"@applicationSchema/schemas": "file:../Boilerplate-application-schema"For a real app, rename the package in the schema repo (e.g. @myAppSchema/schemas) and update package.json + all require() paths here.
The schema package exports:
| Export | Purpose |
|---|---|
initMongo(mongoUri) |
Connect to MongoDB (throws on failure) |
disconnectMongo() |
Graceful disconnect |
isConnected() |
Connection status check |
USER_TYPES |
Shared user type constants |
User |
Mongoose User model (findByCredentials, findByEmailForPassReset) |
Usage in this repo:
// index.js
const { initMongo } = require('@applicationSchema/schemas');
await initMongo(config.mongo.uri);
// server/user/user.helper.js
const { User } = require('@applicationSchema/schemas');Success
{
"success": true,
"message": "User loaded",
"data": { "user": {} },
"meta": { "page": 1, "limit": 10, "total": 42, "pages": 5 }
}Error
{
"success": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid credentials."
}
}Every response includes an X-Request-Id header for log correlation.
| Method | Path | Description |
|---|---|---|
| GET | /health |
Liveness probe |
| GET | /ready |
Readiness probe (MongoDB ping) |
| GET | /metrics |
Prometheus metrics |
| Method | Path | Description |
|---|---|---|
| POST | /user/register |
Register (firstName, email, strong password) |
| POST | /user/login |
Login via User.findByCredentials |
| POST | /user/logout |
Logout (client discards token) |
| Method | Path | Description |
|---|---|---|
| GET | /user-me |
Current user profile |
| GET | /users |
List users (Admin/Superuser only) |
| GET | /user/:userID |
Get user (U-XXXXXXXXXX format) |
| PUT | /user/:userID |
Update user (owner or admin) |
| DELETE | /user/:userID |
Delete user (owner or admin) |
JWT payload includes user_id, email, and userType (U100 Admin, U200 Superuser, etc.).
├── config/ # Config, Express setup, constants
├── server/user/ # Routes → controller → service → helper
├── tests/ # Jest + Supertest (schema mocked in tests)
├── utils/ # Logger, response helpers, metrics
└── index.js # initMongo + graceful shutdown
| Script | Description |
|---|---|
npm start |
Production |
npm run start:local |
Nodemon dev server |
npm test |
Run tests |
npm run lint |
ESLint |
See CONTRIBUTING.md for module conventions.
MIT