A secure and scalable backend API for user authentication built using Node.js, Express.js, and MongoDB.
- User Registration & Login (JWT Auth)
- Passwords hashed with
bcryptjs - Token-based protected routes
- Input validation using
express-validator - Secure headers with
helmet - CORS enabled for frontend integration
- Logging with
morgan - Rate limiting to prevent brute-force attacks
| Technology | Purpose |
|---|---|
| Node.js | JavaScript runtime |
| Express.js | Web framework |
| MongoDB | NoSQL database |
| Mongoose | ODM for MongoDB |
| bcryptjs | Hash passwords securely |
| jsonwebtoken | JWT-based authentication |
| dotenv | Environment variable handling |
| helmet | Set secure HTTP headers |
| cors | Allow cross-origin requests |
| morgan | Request logging in dev mode |
| nodemon | Auto-restart during development |
git clone https://github.com/your-username/lifeline-api.git
cd lifeline-api
npm installCreate a .env file:
PORT=5000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key# Development
npm run dev
# Production
npm startPOST /register
Body:
{
"name": "Balaji",
"email": "balaji@example.com",
"password": "yourPassword"
}POST /login
Body:
{
"email": "balaji@example.com",
"password": "yourPassword"
}Response:
{
"token": "your_jwt_token"
}register()→ Saves user with hashed passwordlogin()→ Verifies password → Sends back JWTauthMiddleware→ Validates token → Grants accessProtected Routes→ Readreq.userfrom decoded token
- Balaji
- GitHub
This project is licensed under the ISC License.
AJ5TTBMBZNEF6QMP2PD4KF92