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)
- 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
git clone https://github.com/CodeTanish/backend-assignment.git
cd backend-assignment npm install npm start PORT=5000
MONGO_URI=mongodb://localhost:27017/<collection name>
JWT_SECRET=your_jwt_secret_key # Change this before productionRegister
POST /api/auth/register
{
"fullName": "test",
"email": "test@example.com",
"password": "password123"
}{
"user": {
"id": "USER_ID",
"fullName": "Tanish Rastogi",
"email": "tanish@example.com"
},
"token": "JWT_TOKEN"
}Login
POST /api/auth/login
{
"fullName": "test",
"email": "test@example.com",
"password": "password123"
}{
"user": {
"id": "USER_ID",
"fullName": "Tanish Rastogi",
"email": "tanish@example.com"
},
"token": "JWT_TOKEN"
}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