This is the backend server for the Social application. It provides API endpoints for managing posts, comments, likes, and notifications.
-
Create a file named
.env
in the root directory of your project. -
Open the
.env
file and add the following environment variables:Replace<your MongoDB URI>
,<your secret key>
,<your Cloudinary name>
,<your Cloudinary API key>
, and<your Cloudinary API secret>
with your actual values.MONGODB_URI=<your MongoDB URI> SECRET_KEY=<your secret key> CLOUDINARY_NAME=<your Cloudinary name> CLOUDINARY_API_KEY=<your Cloudinary API key> CLOUDINARY_API_SECRET=<your Cloudinary API secret>
-
Install the required dependencies by running the following command in your terminal:
npm install
-
Start the development server by running the following command:
npm run dev
This will use
nodemon
to automatically restart the server whenever changes are made to the code. -
Open your browser and visit
http://localhost:3000
to access the application in the development environment.
The application is live on https://social-backend-iota.vercel.app/. To deploy the application, follow these steps:
-
Update the necessary environment variables in your deployment environment or platform with the corresponding values.
-
Build and start the application by running the following command:
npm start
-
The application will be accessible at the specified deployment URL.
This is the backend server for the Social application. It provides API endpoints for managing posts, comments, likes, and notifications.
- URL:
{{ _.base_path }}/
- Method: GET
- Description: Retrieves a welcome message for space cowboys.
-
URL:
{{ _.base_path }}/auth/register
-
Method: POST
-
Description: Registers a new user.
-
Body:
{ "email": "test4@test.com", "password": "123456", "username": "test4" }
-
Headers:
- Content-Type: application/json
-
URL:
{{ _.base_path }}/auth/login
-
Method: POST
-
Description: Logs in a user.
-
Body:
{ "email": "test@test.com", "password": "123456" }
-
Headers:
- Content-Type: application/json
-
URL:
{{ _.base_path }}/users/changeProfile
-
Method: POST
-
Description: Updates the user's profile.
-
Body:
{ "username": "test10" }
-
Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- URL:
{{ _.base_path }}/auth/me
- Method: GET
- Description: Retrieves the user's profile.
- Headers:
- Authorization: Bearer [token]
- URL:
{{ _.base_path }}/users/
- Method: GET
- Description: Retrieves all users.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- URL:
{{ _.base_path }}/users/62f445749c1ca951ce4ca954
- Method: GET
- Description: Retrieves a specific user.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
-
URL:
{{ _.base_path }}/follow/
-
Method: POST
-
Description: Toggles the follow status for a user.
-
Body:
{ "id": "63f148b6db4738dc32a26bbc" }
-
Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- URL:
{{ _.base_path }}/follow
- Method: GET
- Description: Retrieves the list of users being followed.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- Parameters:
- type: following
- username: test
- URL:
{{ _.base_path }}/follow/followers
- Method: GET
- Description: Retrieves the list of followers.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- Parameters:
- username: test
- URL:
{{ _.base_path }}/posts
- Method: GET
- Description: Retrieves all posts.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- Parameters:
- page: 1
- filter: user_posts
- limit:
10
- likes: 1
- sort: desc
- username: test
- before: 2023-01-01
- URL:
{{ _.base_path }}/posts/62f3c0a29c1ca951ce4ca958
- Method: GET
- Description: Retrieves a specific post.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- URL:
{{ _.base_path }}/posts
- Method: POST
- Description: Creates a new post.
- Headers:
- Content-Type: multipart/form-data
- Authorization: Bearer [token]
- Body:
- text: Sample post text
- image: [file]
-
URL:
{{ _.base_path }}/posts/62f3c0a29c1ca951ce4ca958
-
Method: PATCH
-
Description: Updates an existing post.
-
Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
-
Body:
{ "text": "Updated post content" }
- URL:
{{ _.base_path }}/posts/62f3c0a29c1ca951ce4ca958
- Method: DELETE
- Description: Deletes a post.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- URL:
{{ _.base_path }}/posts/62f3c0a29c1ca951ce4ca958/comments
- Method: GET
- Description: Retrieves all comments for a specific post.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
-
URL:
{{ _.base_path }}/posts/62f3c0a29c1ca951ce4ca958/comment
-
Method: POST
-
Description: Creates a new comment on a post.
-
Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
-
Parameters:
- postId: 62f3c0a29c1ca951ce4ca958
-
Body:
{ "text": "Sample comment" }
- URL:
{{ _.base_path }}/posts/62f3c0a29c1ca951ce4ca958/likes
- Method: GET
- Description: Retrieves all likes for a specific post.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]
- URL:
{{ _.base_path }}/posts/62f3c0a29c1ca951ce4ca958/like
- Method: POST
- Description: Toggles the like status for a post.
- Headers:
- Content-Type: application/json
- Authorization: Bearer [token]