- Clone the repository.
- Install dependencies using
npm install
. - Rename
.env.example
to.env
. - Run the server using
npm run dev
.
- Before pushing your code to the remote repository, ensure that you have run the following command in your terminal (Git Bash):
rm -rf .git
- Environment Variables:
PORT
: Port number the server listens on. Default: 3000MONGODB_URI
: URI for MongoDB database.JWT_SECRET
: Secret key for JWT token generation.EXPIRES_IN
: Token expiration time.
- API Endpoints:
-
POST
/api/auth/login
- Description: Authenticates user and returns a JWT token.
- Request:
{ "email": "[email protected]", "password": "password" }
- Response:
{ "success": true, "message": "User registered successfully" }
-
POST
/api/auth/register
- Description: Registers a new user.
- Request:
{ "name": "John", "email": "[email protected]", "password": "password" }
- Response:
{ "success": true, "message": "Login successful", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InBoMkBleGFtcGxlLmNvbSIsImlhdCI6MTcwNzg1MDYyMSwiZXhwIjoxNzA3OTM3MDIxfQ.7EahSgmPLPNuZ_T9ok-B6TayWCJVdxPzi_Nx4UfrhvY" }
-
bcrypt
: Library for hashing passwords.cors
: Express middleware for enabling CORS.dotenv
: Loads environment variables from .env file.express
: Web framework for Node.js.jsonwebtoken
: Library for generating and verifying JWT tokens.mongodb
: MongoDB driver for Node.js.nodemon
: Utility for automatically restarting the server during development.