This project is a basic authentication system developed using Node.js, Express, and MongoDB. It facilitates user registration, login, password reset functionalities, and CRUD operations for social media posts with likes and comments.
Ensure Node.js is installed on your system before proceeding. Download and install Node.js from https://nodejs.org/.
To set up this project locally, follow the steps below:
-
Clone the repository to your local machine or download the project files.
-
Open a terminal, navigate to the project's root directory:
cd path/to/banao-assignment
-
Install the necessary dependencies:
npm install
-
Environment Setup
To run this project, you will need to create a .env
file in the root directory of the project. This file should contain the following environment variables:
MONGO_URI=<Your_MongoDB_URI>
JWT_SECRET=<Your_JWT_Secret>
PORT=<Your_Port_Number>
Here's how to obtain these values:
- Description: This is the connection string to your MongoDB database.
- How to Get:
- Sign up or log in to MongoDB Atlas.
- Create a new cluster or use an existing one.
- Navigate to the "Connect" section of your cluster.
- Choose "Connect your application".
- Copy the connection string provided and replace
<password>
with your database user's password, andmyFirstDatabase
with your database name if necessary.
- Description: A secret key used for signing and verifying JSON Web Tokens (JWT).
- How to Get:
- You can generate a random string. This could be anything, but it's important that it's kept secret. For example, you could use an online tool like RandomKeygen.
- Description: The port number on which your server will listen.
- How to Get:
- You can choose any available port number. Common choices for development are
3000
,5000
, or8000
. Ensure the port you choose is not already in use on your system.
- You can choose any available port number. Common choices for development are
After obtaining these values, replace <Your_MongoDB_URI>
, <Your_JWT_Secret>
, and <Your_Port_Number>
in the .env
file with your actual values.
-
Launch the development server:
npm run dev
Use Postman or another API testing tool to test the API endpoints.
-
Endpoint:
{backend-url}/api/auth/register
-
Method:
POST
-
Body (raw, JSON):
{ "username": "<username>", "email": "<email>", "password": "<password>" }
-
Endpoint:
{backend-url}/api/auth/login
-
Method:
POST
-
Body (raw, JSON):
{ "username": "<username>", "password": "<password>" }
-
Endpoint:
{backend-url}/api/auth/forgot-password
-
Method:
POST
-
Body (raw, JSON):
{ "email": "<email>" }
-
Endpoint:
{backend-url}/api/posts
-
Method:
POST
-
Headers:
- Authorization: Bearer
<token>
- Authorization: Bearer
-
Body (raw, JSON):
{ "content": "<content>" }
- Endpoint:
{backend-url}/api/posts
- Method:
GET
- Endpoint:
{backend-url}/api/posts/:id
- Method:
GET
-
Endpoint:
{backend-url}/api/posts/:id
-
Method:
PUT
-
Headers:
- Authorization: Bearer
<token>
- Authorization: Bearer
-
Body (raw, JSON):
{ "content": "<updated content>" }
- Endpoint:
{backend-url}/api/posts/:id
- Method:
DELETE
- Headers:
- Authorization: Bearer
<token>
- Authorization: Bearer
- Endpoint:
{backend-url}/api/posts/:id/like
- Method:
POST
- Headers:
- Authorization: Bearer
<token>
- Authorization: Bearer
-
Endpoint:
{backend-url}/api/posts/:id/comments
-
Method:
POST
-
Headers:
- Authorization: Bearer
<token>
- Authorization: Bearer
-
Body (raw, JSON):
{ "text": "<comment text>" }
Replace <username>
, <email>
, <password>
, <content>
, <updated content>
, and <comment text>
with actual values when testing the endpoints.