An open API service indexing awesome lists of open source software.

https://github.com/kirankumar-matham96/social-media-backend-api

A Node.js application to create, update, delete posts, comments and likes. Build using REST Full API with user authorization feature.
https://github.com/kirankumar-matham96/social-media-backend-api

archiver express express-validator fs jwt multer node path uuid winston

Last synced: 7 days ago
JSON representation

A Node.js application to create, update, delete posts, comments and likes. Build using REST Full API with user authorization feature.

Awesome Lists containing this project

README

        

# Social Media App (NODE-REST-API)

A Node.js application to create, update, delete posts, comments and likes. Build using REST Full API with user authorization feature.

## Table of Contents

- [Features](#features)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Project Structure](#project-structure)
- [API Endpoints](#api-endpoints)
- [Technologies Used](#technologies-used)
- [Contributing](#contributing)
- [License](#license)

## Features

- 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

## Prerequisites

- Node.js (>=14.x)
- npm (>=6.x)

## Installation

1. Clone the repository:

```bash
git clone https://github.com/kirankumar-Matham96/Social-media-backend-api.git
```

2. Install the dependencies:

```bash
npm install
```

3. Create environments file (.env)

```bash
SECRET_CODE = [Add your secret code here]
PORT = [add port number to run the server]
```

4. Start the application:

- if nodemon is not installed

```bash
npm run start
```

- if nodemon is installed

```bash
npm run dev
```

5. Open your browser and navigate to `http://localhost:[portNumber]`

## Project Structure

```
├── 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
```

## API Endpoints

# NOTE:

- After login, send the "token" header in the request headers to use the apis.
```bash
token:
```

### User Routes

- `POST /signup`: Register a new user
- `POST /signin`: Login a user

### Post Routes

- `POST /api/posts/`: Create a new post
- `GET /api/posts/all`: Get all posts
- `GET /api/posts/all?caption=`: Get all posts with filtering by caption
- `GET /api/posts/all?offset=&limit=`: Change pagination while retrieving the posts
- `GET /api/posts/all?caption=&offset=&limit=`: Change pagination while retrieving the posts filtered by caption
- `GET /api/posts/`: Get a specific post by ID
- `GET /api/posts/`: Get all posts of a user
- `GET /api/posts?caption=`: Get all posts of a user posts filtering by caption
- `GET /api/posts?offset=&limit=`: Change pagination while retrieving the user posts
- `GET /api/posts?caption=&offset=&limit=`: Change pagination while retrieving the user posts filtering by caption
- `PUT /api/posts/`: Update post by ID
- `DELETE /api/posts/`: Delete post by ID
- `PUT /api/posts/bookmark/`: Toggle bookmark a post
- `POST /api/posts/draft/`: save a post as draft (\*.txt)
- `POST /api/posts/archive/`: save a post as zip (\*.zip)

### Comment Routes

- `POST /api/comments/`: Add a new comment
- `GET /api/comments/`: Get all comments related to a post
- `PUT /api/comments/`: Update comment by ID
- `DELETE /api/comments/`: Delete comment by ID

### Like Routes

- `GET /api/likes/`: Get all likes of a post
- `GET /api/likes/toggle/`: Like or dislike a post

## Technologies Used

- 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)

## Contributing

Contributions are welcome! Please follow these steps:

1. Fork the repository
2. Create a new branch (`git checkout -b feature/your-feature`)
3. Commit your changes (`git commit -m 'Add some feature'`)
4. Push to the branch (`git push origin feature/your-feature`)
5. Open a pull request

### NOTE:

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

## License

This project is licensed under the ISC License.

[Comment]< the [LICENSE](LICENSE) file for details.>