Week 2 assignment for BeTechFied — Build & Deploy Your API.
A small Express API with JSON parsing, error handling, an .env-driven port,
a static HTML landing page, and a custom request-logging middleware.
| Method | Route | Description |
|---|---|---|
| GET | / |
Serves a static HTML page ("My Week 2 API!") |
| POST | /user |
Accepts { name, email }, responds "Hello, [name]!" |
| GET | /user/:id |
Responds "User [id] profile" |
POST /user returns 400 if name or email is missing.
npm install
cp .env.example .env # sets PORT (defaults to 3000)
npm startThen open http://localhost:3000
# Home page
curl http://localhost:3000/
# Create user (success)
curl -X POST http://localhost:3000/user \
-H "Content-Type: application/json" \
-d '{"name":"Tobi","email":"tobi@example.com"}'
# Missing data -> 400
curl -X POST http://localhost:3000/user \
-H "Content-Type: application/json" \
-d '{"name":"Tobi"}'
# Get user profile
curl http://localhost:3000/user/42- ✅ JSON body parsing (
express.json()) - ✅ Error handling (400 for missing data / bad requests)
- ✅
.envforPORT - ✅ Static HTML page served at
/ - ✅ Bonus: custom middleware logging every request