Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

week2-node-express

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.

Endpoints

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.

Setup

npm install
cp .env.example .env   # sets PORT (defaults to 3000)
npm start

Then open http://localhost:3000

Testing with curl

# 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

Features

  • ✅ JSON body parsing (express.json())
  • ✅ Error handling (400 for missing data / bad requests)
  • .env for PORT
  • ✅ Static HTML page served at /
  • Bonus: custom middleware logging every request

About

Week 2 BeTechFied assignment: Express API (GET /, POST /user, GET /user/:id) with JSON parsing, error handling, .env PORT, static page, and request logging middleware

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages