A secure, production-ready REST API built with Node.js, Express.js, and MongoDB that enables authenticated users to perform bulk status operations across the entire user base.
The User Status Toggle API demonstrates:
The system allows authenticated users to toggle the status of all users in a single atomic operation using MongoDB bulk updates.
When the toggle endpoint is triggered:
If the majority of users are active β all users become inactive
If the majority of users are inactive β all users become active
β Executed via a single bulk update
β Optimized for scalability
β Designed for production reliability
Client
β
βΌ
Express Router
β
βΌ
Controller Layer
β
βΌ
MongoDB (via Mongoose)
βββ src/
β βββ controllers/
β βββ models/
β βββ routes/
β βββ middleware/
β βββ app.js
βββ .env
βββ package.json
βββ README.md
| Layer | Technology |
|---|---|
| Runtime | Node.js |
| Framework | Express.js |
| Database | MongoDB |
| ODM | Mongoose |
| Authentication | JWT |
| Security | bcrypt |
git clone https://github.com/your-username/Auth-Application.git <br/>
cd Auth-Application
npm install
PORT=5000
MONGO_URI=your_mongodb_uri
JWT_SECRET=super_secure_jwt_secret
| Variable | Description |
|---|---|
| PORT | Application runtime port |
| MONGO_URI | MongoDB connection string (local or cloud) |
| JWT_SECRET | Secret key used for signing JWT tokens |
npm start
http://localhost:5000
POST /api/auth/signup
{
"email": "john@example.com",
"password": "password123"
}
POST /api/auth/login
{
"email": "john@example.com",
"password": "password123"
}
Returns:
{
"token": "jwt_token_here"
}
POST /api/users/toggle-status
Requires header:
Authorization: Bearer <jwt_token>
Performs a bulk update across all user records.
User registers
User logs in β receives JWT
User calls protected toggle endpoint
All usersβ statuses flip via bulk update
Before deploying:
Use a strong JWT secret
Use a secure MongoDB URI
Enable HTTPS in production
Configure proper logging
Validate environment variables
Implement rate limiting (recommended)
Add input validation middleware
This repository is open to contributions.
You can contribute to:
Currently, there are no open issues.
If you would like to:
Improve UI
Enhance server logic
Add new features
Refactor architecture
Please open an issue first to discuss your proposal before implementation.
Collaborative discussion ensures consistency and quality.
Planned Improvements:
If this project helps you:
Give it a β on GitHub.
Contributions, feedback, and architectural suggestions are welcome.

