An API for a social network web application where users can share thoughts, react and create a friend list. Express.js is used for routing. MongoDB is used for the database along with Mongoose ODM
AS A social media startup
I WANT an API for my social network that uses a NoSQL database
SO THAT my website can handle large amounts of unstructured data
- Clone this repository to your local computer.
- Open the repo in VS Code.
- Open the index.js file in the Integrated Terminal.
- Type the following in the command line:
npm i
- Create your own
.env
file with the following content:
MONGODB_URI = '(mongodbconnection)/mydatabase'
- Replace the content between the single quotation marks
' '
in your MongoDB URL connection in the.env
file. - Type the following in the command line:
node index.js
- Use Insomnia to test the application functionality. Below are all routes to test:
/api/users
GET
all usersGET
a single user by its_id
POST
a new user (See example data for new user)PUT
to update a user by its_id
DELETE
to remove a user by its_id
// example data for new user
{
"username": "lernantino",
"email": "[email protected]"
}
-
/api/users/:userId/friends/:friendId
POST
to add a new friend to a user's friend listDELETE
to remove a friend from a user's friend list
-
/api/thoughts
GET
to get all thoughtsGET
to get a single thought by its_id
POST
to create a new thought (See example data for new thought)PUT
to update a thought by its_id
DELETE
to remove a thought by its_id
// example data for new thought
{
"thoughtText": "Here's a cool thought...",
"username": "lernantino",
"userId": "5edff358a0fcb779aa7b118b"
}
/api/thoughts/:thoughtId/reactions
POST
to create a reaction stored in a single thought'sreactions
array fieldDELETE
to pull and remove a reaction by the reaction'sreactionId
value
Please see the demo on YouTube.
MIT This project is licensed under MIT.
My instructor, Saurav Khatiwada.
- GitHub: njthanhtrang
- freeCodeCamp: Introduction to Mongoose for MongoDB
- Mastering JS: How to Validate Unique Emails with Mongoose
- MongoDB: CRUD Operations
- Mozilla: Express Tutorial Part 4: Routes and controllers
- StackOverflow: How To Create Mongoose Schema with Array of Object IDs?
- StackOverflow: how to use getter or setter with mongoose timestamps?
- StackOverflow: Removing white spaces (leading and trailing) from string value
- StackOverflow: Route.get() requires callback functions but got a "object Undefined"
Click links to read the documentation for each dependency: