Task was to build an API for a social network web application where users can share their thoughts, react to friends’ thoughts, and create a friend list. The required stack includes Express.js for routing, a MongoDB database, and the Mongoose ODM. In addition to using the Express.js and Mongoose packages, I have also used a native JavaScript Date object and Web API to format timestamps.
I have created a walkthrough video that demonstrates the functionality of the API using Insomnia after creating the API. A link to the video has been provided in the README below.
- Description
- Installation
- Usage
- Directory Structure
- Technologies Used
- Setup
- Demo
- Acknowledgements
- Questions
- License
Install dependencies using:
npm install
Need to have MongoDB and MongoDB Compass installed locally to run the app.
The application will then be invoked by using the following command:
npm run watch
.
├── config/
├── controllers/
├── models/
│ ├── Thought.js
│ ├── User.js
│ └── index.js
├── routes/
│ ├── api/
| | ├── thoughtRoutes.js
| | ├── userRoutes.js
| | └── index.js
│ └── index.js
├── utils/
├── .gitignore
├── README.md
├── LICENSE
├── package.json
├── README.md
└── index.js- Node.js
- Express.js
- MongoDB
- Mongoose (ODM)
- Nodejs must be installed
- MongoDB Compass must be installed
- Insomnia was used to test routes
- Text editor (VS Code recommended)
This demos a general overview of the functionality of the api, and starts by demonstrating on how to invoke the application. I then explain how Mongoose syncs to MongoDB on server start, and go over the User and Thought models and their associated schemas and subdocuments. I also provide an brief over the getter method used to format dates, virtuals used, referenced models, self-references, and the objectId method to create a unique id value with a desired name:
This demos POST User, POST Thought, POST friend, POST Reaction, GET Single User, GET Single Thought, Get All Thoughts, GET All Users. This also showcases a match validation for an incorrect email and formatted dates:
/api/users
GETall usersGETa single user by its_idand populated thought and friend dataPOSTa new user
/api/users/userId
PUTto update a user by its_id
/api/users/:userId/friends/:friendId
POSTto add a new friend to a user's friend list
/api/thoughts
GETto get all thoughtsGETto get a single thought by its_idPOSTto create a new thought (This also pushes the created thought's_idto the associated user'sthoughtsarray field)
/api/thoughts/:thoughtId/reactions
POSTto create a reaction stored in a single thought'sreactionsarray field
This demos PUT Thought, POST friend (second), DELETE friend:
/api/thoughts/thoughtId
PUTto update a thought by its_id
/api/users/:userId/friends/:friendId
DELETEto remove a friend from a user's friend list
This demos DELETE Reaction, DELETE Thought, DELETE User (and associated thoughts):
/api/thoughts/:thoughtId/reactions
DELETEto pull and remove a reaction by the reaction'sreactionIdvalue
/api/thoughts/thoughtId
DELETEto remove a thought by its_id
/api/users/userId
DELETEto remove user by its_idand removes a user's associated thoughts when deleted.
- https://www.npmjs.com/package/mongoose
- https://www.npmjs.com/package/express
- https://www.npmjs.com/package/nodemon
Created by: @moedaaboul
Feel free to contact me via muhammad.daaboul1989@gmail.com!
This work is licensed under MIT.



