1 Node.js Basics
require vs import
process.env, __dirname, fs
path module
process object
npm scripts
2 Express Setup
Minimal Express Server
Router file pattern
3 Route Methods
GET / POST / PUT / PATCH / DELETE
Query strings & body
4 req & res
req — request object
res — response object
5 Middleware
Middleware Signature & app.use
CORS, express.json, rate limiting
6 Error Handling
4-arg Error Middleware & asyncHandler
Error patterns in routes
7 PostgreSQL (pg)
Pool Setup & pool.query
Parameterized Queries & RETURNING
Transactions
Common SQL Patterns
8 JWT Auth
Sign & Verify
Auth Middleware & Login Route
9 REST Status Codes
| Code | Name | When to use | Example |
|---|---|---|---|
| 200 | OK | Successful GET, PATCH, DELETE, PUT | Product fetched, cart updated |
| 201 | Created | Successful POST that created a resource | New user registered, order placed |
| 204 | No Content | Success with no body (often DELETE) | Item deleted, logout succeeded |
| 400 | Bad Request | Malformed request syntax or missing data | Unparseable JSON body, wrong data type |
| 401 | Unauthorized | Not authenticated — token missing or invalid | No Bearer token, expired JWT |
| 403 | Forbidden | Authenticated but not allowed (wrong role) | User tries to access admin route |
| 404 | Not Found | Resource doesn't exist | Product ID not in DB, route not registered |
| 409 | Conflict | State conflict — duplicate or version mismatch | Email already registered, duplicate order |
| 422 | Unprocessable Entity | Syntactically valid but semantically wrong | price is negative, email format invalid |
| 500 | Internal Server Error | Unexpected server crash / unhandled exception | DB connection failed, uncaught error |
| 503 | Service Unavailable | Server temporarily unavailable | Maintenance mode, DB overloaded |
Quick rule: 2xx = success, 4xx = client made a mistake, 5xx = server made a mistake. Always return a JSON body with an
error field for 4xx/5xx so the client can display a useful message.
REST Conventions
Response Shape
Common .env Variables
Africa & India's Best AI Academy
You know the backend.
Now build and deploy full-stack APIs.
Join the Best AI Programs — three 5-month courses, fully online, with placement assistance. Week 1 is free.
Explore our AI-era courses →