render link: https://happy-thoughts-api-o47r.onrender.com
This project is a RESTful API built with Node.js, Express, and MongoDB (via Mongoose) that allows users to create, view, manage, and "like" happy thoughts. It also includes user authentication features to secure content management actions.
- User Management:
- Signup: Register new users with email, first name, last name, and hashed passwords (using
bcrypt). - Login: Authenticate users and receive an
accessTokenfor protected requests.
- Signup: Register new users with email, first name, last name, and hashed passwords (using
- Happy Thoughts Management:
- Create: Authenticated users can post happy thoughts.
- Read: View all thoughts (supports filtering by minimum likes) or fetch a specific thought by ID.
- Update: Authenticated users can edit their own thoughts.
- Delete: Authenticated users can delete their own thoughts.
- Like: Users can "like" (increment the heart count) any happy thought.
- Security:
- Authentication middleware verifies user
accessTokenfor sensitive operations (creating, updating, deleting). - Authorization checks ensure users can only modify thoughts they own.
- Password hashing and email validation.
- Authentication middleware verifies user
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB
- ODM: Mongoose
- Security:
bcrypt(password hashing),crypto(access token generation) - Utilities:
cors,dotenv(environment variables),express-list-endpoints
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/signup |
Register a new user | No |
POST |
/login |
Authenticate user | No |
GET |
/:id |
Get user profile | No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/ |
List thoughts (query: minLikes) |
No |
POST |
/ |
Create a new thought | Yes |
GET |
/:id |
Get a specific thought | No |
PATCH |
/:id |
Update a thought | Yes |
DELETE |
/:id |
Delete a thought | Yes |
PATCH |
/:id/like |
Like a thought | No |
- Clone the repository.
- Install dependencies:
npm install
- Environment Variables:
Create a
.envfile in the root directory and define the following:MONGO_URL=your_mongodb_connection_string - Run the server:
npm run dev