https://github.com/sandeepguptax2003/banao-nodejs-task-1
This project is a Node.js backend application that provides user authentication APIs using Express.js and MongoDB.
https://github.com/sandeepguptax2003/banao-nodejs-task-1
bcryptjs expressjs jwt-authentication nodejs
Last synced: 2 months ago
JSON representation
This project is a Node.js backend application that provides user authentication APIs using Express.js and MongoDB.
- Host: GitHub
- URL: https://github.com/sandeepguptax2003/banao-nodejs-task-1
- Owner: sandeepguptax2003
- Created: 2024-07-10T15:40:46.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-10T17:41:07.000Z (11 months ago)
- Last Synced: 2025-02-01T22:47:53.102Z (4 months ago)
- Topics: bcryptjs, expressjs, jwt-authentication, nodejs
- Language: JavaScript
- Homepage: https://banao-nodejs-task-1.onrender.com/
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# User Authentication API
This project is a Node.js backend application that provides user authentication APIs using Express.js and MongoDB.
## Features
- User registration
- User login
- Forgot password functionality
- JWT-based authentication## Prerequisites
- Node.js
- MongoDB
- Express.js## Installation
1. Clone the repository:
```bash
git clone https://github.com/yourusername/user-authentication-api.git
cd user-authentication-api
```2. Install dependencies:
```bash
npm install
```3. Create a `.env` file in the root directory with the following content:
```env
PORT=4000
MONGODB_URI=mongodb://localhost:27017/your_database_name
JWT_SECRET=your_jwt_secret_key
```
Replace `your_database_name` and `your_jwt_secret_key`.4. Start the server:
```bash
nodemon server.js
```## API Endpoints
### 1. User Registration
- **URL:** `/register`
- **Method:** POST
- **Body:**
```json
{
"username": "testuser",
"email": "[email protected]",
"password": "password123"
}
```
- **Success Response:**
```json
{
"code": 201,
"content": { "message": "User registered successfully" }
}
```### 2. User Login
- **URL:** `/login`
- **Method:** POST
- **Body:**
```json
{
"username": "testuser",
"password": "password123"
}
```
- **Success Response:**
```json
{
"code": 200,
"content": {
"message": "Login Successful",
"token": "your_jwt_token_here"
}
}
```### 3. Forgot Password
- **URL:** `/forgot-password`
- **Method:** POST
- **Headers:**
```http
Authorization: Bearer your_jwt_token_here
```
- **Body:**
```json
{
"email": "[email protected]"
}
```
- **Success Response:**
```json
{
"code": 200,
"content": { "message": "Password reset email sent (simulated)" }
}
```### 4. Home Route
- **URL:** `/`
- **Method:** GET
- **Success Response:**
```json
{
"code": 200,
"content": "Welcome to user home page"
}
```## Testing
You can use tools like Postman or Thunder Client to test the APIs. Here's how to test each route:
1. Register a new user
2. Login with the registered user to get a JWT token
3. Use the JWT token in the Authorization header for the forgot password routeNote: The forgot password functionality simulates sending an email. Check the server console for the reset token log.
## Technologies Used
- Node.js
- Express.js
- MongoDB
- Mongoose
- JSON Web Tokens (JWT)
- bcrypt.js## Security Notes
- Passwords are hashed before storing in the database.
- JWT is used for authentication.
- The forgot password route is protected and requires authentication.## License
This project is licensed under the MIT License.