Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔐 User Authentication Backend (Express.js + MongoDB + JWT)

This is a secure and modular authentication backend built with Node.js, Express, and MongoDB, supporting:

  • ✅ User Registration (Full Name, Email, Password)
  • ✅ Login with input validation
  • ✅ Password hashing with bcryptjs
  • ✅ JWT-based token authentication
  • ✅ Modular file structure (Controllers, Services, Routes, Models)

🛠️ Tech Stack

  • Node.js – runtime environment
  • Express.js – web framework
  • MongoDB + Mongoose – database & object modeling
  • bcryptjs – password hashing
  • jsonwebtoken – authentication with JWT
  • express-validator – request validation
  • dotenv – environment config

📦 Setup Instructions

1. Clone the repository

git clone https://github.com/CodeTanish/backend-assignment.git
cd backend-assignment

Install dependencies

 npm install 

Run the server

 npm start 

Create .env file in the root directory

PORT=5000
MONGO_URI=mongodb://localhost:27017/<collection name>
JWT_SECRET=your_jwt_secret_key  # Change this before production

API Endpoints

Register

POST /api/auth/register

{
  "fullName": "test",
  "email": "test@example.com",
  "password": "password123"
}

Response Output

{
  "user": {
    "id": "USER_ID",
    "fullName": "Tanish Rastogi",
    "email": "tanish@example.com"
  },
  "token": "JWT_TOKEN"
}

API Endpoints

Login

POST /api/auth/login

{
  "fullName": "test",
  "email": "test@example.com",
  "password": "password123"
}

Response Output

{
  "user": {
    "id": "USER_ID",
    "fullName": "Tanish Rastogi",
    "email": "tanish@example.com"
  },
  "token": "JWT_TOKEN"
}

Project Structure

backend-assignment/
├── config/              # Database connection
│   └── db.js
├── controllers/         # Business logic handlers
│   └── user.controller.js
├── models/              # Mongoose schemas
│   └── user.model.js
├── routes/              # Express route definitions
│   └── user.router.js
├── services/            # Service layer logic
│   └── user.service.js
├── utils/               # Utility functions
│   └── jwt.js
├── .env                 # Environment variables
├── server.js            # App entry point
└── package.json

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages