This project is a Social Network API built using Express.js, MongoDB, and Mongoose. It allows users to share thoughts, react to others' thoughts, and manage friend lists. The API offers various functionalities like creating, updating, deleting users and thoughts, adding and removing friends, and handling reactions to thoughts. This project was developed to practice working with NoSQL databases, API routing, and MongoDB.
-Clone the repository to your local machine:
Copy
git clone
-Navigate to the project folder:
cd social-network-api
-Install the dependencies:
npm install
-Set up your environment variables (e.g., MongoDB connection string) in a .env file.
-Run the server:
npm start
The server will start, and the Mongoose models will be synced to the MongoDB database.
🚀 1. Add a New Request in Insomnia
-Open Insomnia.
-Click "New Request" → Name it (e.g., "Create User") → Select POST → Click Create.
👤 2. Create a New User (POST /api/users)
URL: http://localhost:3001/api/users Body (JSON):
{
"username": "daniel",
"email": "[email protected]"
}
In Insomnia: Select Body → JSON. Paste the JSON above. Click Send.
📋 3. Get All Users (GET /api/users)
URL: http://localhost:3001/api/users Click Send. Response: A list of all users in the database.
👤 4. Get a Single User (GET /api/users/:userId)
URL: http://localhost:3001/api/users/{userId} (replace {userId} with an actual ID) Click Send.
✏ 5. Update a User (PUT /api/users/:userId)
URL: http://localhost:3001/api/users/{userId} Body (JSON):
{
"username": "daniel_updated",
"email": "[email protected]"
}
Click Send.
❌ 6. Delete a User (DELETE /api/users/:userId)
URL: http://localhost:3001/api/users/{userId} Click Send.
🤝 7. Add a Friend (POST /api/users/:userId/friends/:friendId)
URL: http://localhost:3001/api/users/{userId}/friends/{friendId} Click Send.
💔 8. Remove a Friend (DELETE /api/users/:userId/friends/:friendId)
URL: http://localhost:3001/api/users/{userId}/friends/{friendId} Click Send.
🧠 9. Create a Thought (POST /api/thoughts)
URL: http://localhost:3001/api/thoughts Body (JSON):
{
"thoughtText": "This is my first thought!",
"username": "daniel",
"userId": "userId_here"
}
Click Send.
This project is licensed under the MIT License - see the LICENSE file for details.




