iyf-s10-week-10-mwas12345spec

Week 10: CommunityHub Backend API

Author

Project Description

This project is a backend REST API for CommunityHub built using Node.js and Express.

The goal of this project was to learn backend fundamentals by building a server, creating routes, implementing CRUD operations, using middleware, handling errors, organizing code into modules, and working with environment variables.

The API allows users to:


Technologies Used


Features


How to Run

  1. Clone this repository
git clone https://github.com/your-github-username/iyf-s10-week-10-your-github-username.git
  1. Navigate into the project folder
cd iyf-s10-week-10-your-github-username
  1. Install dependencies
npm install
  1. Start the server
npm start

OR

node server.js
  1. Test the API at:
http://localhost:3000/api/posts

API Endpoints

Get all posts

GET /api/posts

Get one post

GET /api/posts/:id

Create a post

POST /api/posts

Update a post

PUT /api/posts/:id

Delete a post

DELETE /api/posts/:id

Like a post

PATCH /api/posts/:id/like

Lessons Learned

Through this project I learned:


Challenges Faced

Challenge 1: Understanding CRUD logic

Initially it was difficult understanding how GET, POST, PUT, and DELETE work together.

Solution:

Practiced each route individually and tested each endpoint.


Challenge 2: Organizing project files

Separating routes, controllers, middleware, and data was confusing.

Solution:

Used a modular project structure to keep the code organized.


Challenge 3: Handling validation errors

POST requests failed when data was incomplete.

Solution:

Added validation middleware to check request data before saving posts.


Challenge 4: Debugging Express errors

Some routes returned errors due to syntax and route mistakes.

Solution:

Used console logging, error middleware, and incremental testing.

Live Demo

View Live Demo