A secure, scalable, and testable backend application built with Express.js and MongoDB Atlas. Includes authentication with email-based verification, password reset, rate limiting, and unit testing.
- โ User Registration with Email Verification (Nodemailer)
- ๐ Secure Login with JWT
- โป๏ธ Email-based Password Reset Flow
- โ๏ธ Rate Limiting with
express-rate-limit - ๐งช Unit Testing with Jest + Supertest
- โ Prevents Simultaneous Logins
- ๐ก๏ธ Environment Variables via
.env - ๐ MongoDB Atlas Integration
- Node.js
- Express.js
- MongoDB (Atlas)
- Mongoose
- Nodemailer (Gmail App Password)
- dotenv
- express-rate-limit
- Jest + Supertest
The backend architecture includes:
- Express.js server handling API requests.
- MongoDB Atlas for data persistence.
- JWT-based authentication for secure access.
- Email services for verification and password reset.
- Middleware for authentication and rate limiting.
git clone https://github.com/Hackur45/secure-backend.git
cd secure-backendnpm installPORT=5500
MONGO_URI=your_mongo_connection_string
JWT_SECRET=your_jwt_secret
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_passwordnpm startServer runs on http://localhost:5500
Registers a new user by accepting an email address. Sends a verification email with a token to confirm the user's email address.
See Postman Screenshot:
Verifies the user's email using the token sent via email and sets the user's password. Marks the account as verified.
See Postman Screenshot:

Authenticates a user with email and password. Returns a JWT token upon successful login for session management.
See Postman Screenshot:
Initiates a password reset by generating a reset token and sending a reset email to the user.
See Postman Screenshot:
Resets the user's password using the valid reset token and new password provided.
See Postman Screenshot:
A protected route that requires a valid Bearer token (JWT). Returns a welcome message and the authenticated user's ID.
See Postman Screenshot:
npm testRuns unit tests using Jest + Supertest.
- Use Gmail App Passwords (not your main password) for Nodemailer.
- Reset token and verification token are time-limited and secure.
- Rate limiting protects against abuse on login and registration routes.
Please refer the Postman teting Routes.txt file for more clarification about the routes.
As always, I'm a bit lazy when it comes to the frontend โ so if you're up for it, feel free to contribute! I'd love to see a minimal UI built for these authentication routes.
This repository is MIT licensed and open to all.
Pull requests are welcome!
Happy Coding! ๐
