This repository is a simple Node.js/Express application that provides a RESTful API
for basic banking user flows. It includes user registration and login endpoints,
MongoDB persistence with mongoose, request logging middleware, and remote log
shipping to SolarWinds Observability.
index.js # Application entry point
config/
db.js # MongoDB connection helper
solarwinds.js # SolarWinds Observability log shipper
controllers/
auth.controller.js # Route handlers for user registration and login
models/
user.model.js # Mongoose schema for users
middleware/
logger.middleware.js # Request logging middleware (ships logs to SolarWinds)
routes/
auth.routes.js # Express router for user endpoints
- index.js: bootstraps the server, loads environment variables via
dotenv, applies middleware (CORS, JSON body parsing, and request logging), and registers the/usersrouter. - config/db.js: connects to MongoDB using the
MONGO_URIenv variable. - config/solarwinds.js: exports
sendToSolarWinds()— ships structured log entries to SolarWinds Observability viaaxiosusing theSOLARWINDS_TOKENenv variable. - models/user.model.js: defines
Userfields —fullName,email,password,accountNumber— with timestamps. - controllers/auth.controller.js: contains
registerUserandloginUserhandlers. - routes/auth.routes.js: wires auth controller functions to
POST /registerandPOST /login. - middleware/logger.middleware.js: on every completed response, records
method, URL, status code, and duration, then forwards the structured payload
to
sendToSolarWinds.
-
Install dependencies:
pnpm install
-
Create a
.envfile in the root:PORT=3000 MONGO_URI=mongodb://localhost:27017/mydb SOLARWINDS_TOKEN=your_solarwinds_ingestion_token
SOLARWINDS_TOKENis optional. If omitted, logs are silently skipped and only printed to the console. -
Run the server:
pnpm dev # development (nodemon) pnpm start # production
-
The API will be available at
http://localhost:3000.
| Method | Path | Description |
|---|---|---|
| GET | / |
Health check — returns welcome text |
| POST | /users/register |
Register a new banking user |
| POST | /users/login |
Login a user |
Request body:
{
"fullName": "John Doe",
"email": "john@example.com",
"password": "123456",
"accountNumber": 11223344
}Response 201:
{
"message": "User registered successfully",
"data": {
"id": "...",
"fullName": "John Doe",
"email": "john@example.com",
"accountNumber": 11223344,
"createdAt": "..."
}
}Request body:
{
"email": "john@example.com",
"password": "123456"
}Response 200:
{
"message": "Login successful",
"data": {
"id": "...",
"fullName": "John Doe",
"email": "john@example.com",
"accountNumber": 11223344
}
}Response 401:
{ "message": "Invalid email or password" }| Package | Purpose |
|---|---|
| Express.js | HTTP server & routing |
| Mongoose | MongoDB ODM |
| dotenv | Environment variable loading |
| axios | HTTP client for SolarWinds log shipping |
| cors | Cross-Origin Resource Sharing middleware |
| nodemon | Auto-restart during development |
Every completed HTTP request is captured by logger.middleware.js and sent as
a structured JSON payload to
SolarWinds Observability:
{
"timestamp": "2026-03-03T06:51:04.381Z",
"method": "POST",
"url": "/users/login",
"statusCode": 200,
"durationMs": 46,
"message": "2026-03-03T06:51:04.381Z | POST /users/login | 200 | 46ms"
}Set SOLARWINDS_TOKEN in .env to enable shipping. If the token is absent,
logs are skipped silently.
- Login is intentionally implemented without security (no password hashing, tokens, or session management), based on the lab objective.
- Feel free to extend the codebase with password hashing (bcrypt), JWT/session based auth, and role-based authorization.