A robust REST API for managing an Employee Management System built with Node.js, Express, and MongoDB.
- Authentication: JWT-based secure authentication & role-based route authorization.
- Master Data Management: Full CRUD operations for Employees, Designations, Locations, Departments, Clients, Projects, and Purchase Orders (POs).
- Transaction Management: Endpoints for Leave Requests, Project Resource Allocations, and PO Allocations Tracking.
- Swagger Documentation: Live, interactive API documentation exposed via Swagger UI.
- Seed Script: Built-in script to instantly deploy fully populated relational dummy data.
- Node.js & Express.js
- MongoDB (Mongoose ODM)
- JSON Web Tokens (JWT)
- Bcryptjs (password hashing)
- Swagger UI (
swagger-jsdoc&swagger-ui-express)
├── config/ # Configuration files (Database connection)
├── controllers/ # API Route Handlers (Logic)
├── middleware/ # Custom auth, role, and error handling middleware
├── models/ # Mongoose DB Schemas
├── routes/ # Express API Route definitions
├── swagger/ # Swagger UI config & schema definitions
├── .env # Environment variables (DB URI, JWT Secret)
├── seed.js # Database dummy data injection script
└── server.js # Main application entry point
- Node.js installed
- MongoDB connection string (Local or MongoDB Atlas)
-
Install dependencies:
npm install
-
Configure environment variables. Create a
.envfile in the root with:PORT=5000 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key
-
(Optional) Run the seed script to populate test data into your database.
node seed.js
Development Mode (Nodemon):
npm run devProduction Mode:
npm startThe system operates with 4 distinct roles, saved in the database as numbers:
1- Super Admin2- Manager3- Team Lead4- Employee
When logging in utilizing the seeded data, you can authenticate via the /api/auth/login endpoint using:
- Super Admin:
admin@ems.com/password123 - Employee:
john.doe@ems.com/password123
Once the server is running, the interactive Swagger UI can be found at:
👉 http://localhost:5000/api-docs
The Swagger UI provides real-time testing capabilities and data schemas for:
/api/auth/api/employees/api/designations/api/locations/api/departments/api/clients/api/projects/api/pos/api/leaves/api/allocations/api/po-allocations