A Node.js application to create, update, delete posts, comments and likes. Build using REST Full API with user authorization feature.
- Features
- Prerequisites
- Installation
- Project Structure
- API Endpoints
- Technologies Used
- Contributing
- License
- User registration and login
- input validations are handled
- Create, update, retrieve by id, filter by user, and all retrieve posts
- Sort by Date feature is added for posts
- Can bookmark a post
- Can save post as a draft
- Can archive a post
- While retrieving the posts:
- user can send a query "caption" to filter the posts by post caption
- user can send a query "limit"(default value = 0) and "offset"(default value = 10) to change pagination settings
- Add, update and retrieve by id, retrieve by post id, and retrieve all the comments
- While retrieving the comments:
- user can send a query "limit"(default value = 0) and "offset"(default value = 10) to change pagination settings
- Like and dislike the post
- Pagination is added for posts and comments
- Node.js (>=14.x)
- npm (>=6.x)
-
Clone the repository:
git clone https://github.com/kirankumar-Matham96/Social-media-backend-api.git
-
Install the dependencies:
npm install
-
Create environments file (.env)
SECRET_CODE = [Add your secret code here] PORT = [add port number to run the server]
-
Start the application:
-
if nodemon is not installed
npm run start
-
if nodemon is installed
npm run dev
- Open your browser and navigate to
http://localhost:[portNumber]
├── src/
│ ├── archives/
│ ├── drafts/
│ ├── features/
| | ├── comments/
│ │ │ ├── controllers/
│ │ │ | └── comment.controller.js
│ │ │ ├── models/
│ │ │ | └── comment.model.js
│ │ │ └── routes/
│ │ | └── comment.routes.js
| | ├── likes/
│ │ │ ├── controllers/
│ │ │ | └── like.controller.js
│ │ │ ├── models/
│ │ │ | └── like.model.js
│ │ │ └── routes/
│ │ │ └── like.routes.js
| | ├── posts/
│ │ │ ├── controllers/
│ │ │ | └── post.controller.js
│ │ │ ├── models/
│ │ │ | └── post.model.js
│ │ │ └── routes/
│ │ | └── post.routes.js
| | └── users/
│ │ ├── controllers/
│ │ | └── user.controller.js
│ │ ├── models/
│ │ | └── user.model.js
│ │ └── routes/
│ │ └── user.routes.js
│ ├── helpers/
| | └── post.helper.js
│ ├── media/
│ └── middlewares/
│ └── customErrorHandling.middleware.js
│ └── fileUpload.middleware.js
│ └── jwtAuth.middleware.js
│ └── logger.middleware.js
├── .env
├── .gitignore
├── package-lock.json
├── package.json
├── README.md
└── server.js
- After login, send the "token" header in the request headers to use the apis.
token: <TOKEN_FROM_THE_LOGIN_RESPONSE>
POST /signup: Register a new userPOST /signin: Login a user
POST /api/posts/: Create a new postGET /api/posts/all: Get all postsGET /api/posts/all?caption=<CAPTION_TO_FILTER_POSTS>: Get all posts with filtering by captionGET /api/posts/all?offset=<POSTS_TO_SKIP>&limit=<MAX_POSTS>: Change pagination while retrieving the postsGET /api/posts/all?caption=<CAPTION_TO_FILTER_POSTS>&offset=<POSTS_TO_SKIP>&limit=<MAX_POSTS>: Change pagination while retrieving the posts filtered by captionGET /api/posts/<POST_ID>: Get a specific post by IDGET /api/posts/: Get all posts of a userGET /api/posts?caption=<CAPTION_TO_FILTER_POSTS>: Get all posts of a user posts filtering by captionGET /api/posts?offset=<POSTS_TO_SKIP>&limit=<MAX_POSTS>: Change pagination while retrieving the user postsGET /api/posts?caption=<CAPTION_TO_FILTER_POSTS>&offset=<POSTS_TO_SKIP>&limit=<MAX_POSTS>: Change pagination while retrieving the user posts filtering by captionPUT /api/posts/<POST_ID>: Update post by IDDELETE /api/posts/<POST_ID>: Delete post by IDPUT /api/posts/bookmark/<POST_ID>: Toggle bookmark a postPOST /api/posts/draft/<POST_ID>: save a post as draft (*.txt)POST /api/posts/archive/<POST_ID>: save a post as zip (*.zip)
POST /api/comments/<POST_ID>: Add a new commentGET /api/comments/<POST_ID>: Get all comments related to a postPUT /api/comments/<COMMENT_ID>: Update comment by IDDELETE /api/comments/<COMMENT_ID>: Delete comment by ID
GET /api/likes/<POST_ID>: Get all likes of a postGET /api/likes/toggle/<POST_ID>: Like or dislike a post
- Node.js
- Express
- jsonwebtoken (for auth)
- Multer (for file handling)
- express-validator (for handling validations)
- winston (for logs)
- archiver (to archive posts)
- uuid (for unique id generation)
- fs (for handling files)
- path (for handling file paths)
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/your-feature) - Open a pull request
please use prefixes for the commit messages as fallowing:
- feat: for adding a feature
- bug-fix: for fixing a bug
- update: for any update
- refracted: for any logic or syntax modifications
This project is licensed under the ISC License.
[Comment]< the LICENSE file for details.>