A backend service built with Node.js, Express, and MongoDB (using Mongoose). The service provides a robust RESTful API for managing users and products while ensuring secure authentication and role-based access control. A simple dashboard is also included to help manage data visually.
- User & Product Management:
- Full CRUD operations for users and products.
- Secure Authentication:
- Uses JSON Web Tokens (JWT) for authentication.
- Passwords are securely hashed with bcrypt.
- Role-Based Access Control:
- Enforces different access levels (Admin, Seller, Customer) for various endpoints.
- Clean and Modular Architecture:
- Easy to extend and maintain.
- Backend: Node.js, Express.js
- Frontend: Ejs
- Database: MongoDB with Mongoose
- Authentication: JWT, bcrypt.js
- Utilities: dotenv, nodemon, morgan, cors
-
Clone the Repository:
git clone https://github.com/yourusername/BlueMedix.git cd BlueMedix
-
Install Dependencies:
npm install
-
Configure Environment Variables: Create a
.env
file in the root directory with the following:PORT=3000 MONGO_URI=mongodb://localhost:27017/bluemedix JWT_SECRET=your_jwt_secret
-
Run the Application:
npm run dev
The server should now run on
http://localhost:3000
and connect to your MongoDB instance.
-
Register User:
- Method: POST
- URL:
/api/auth/register
- Description: Creates a new user.
-
Login User:
- Method: POST
- URL:
/api/auth/login
- Description: Authenticates a user and returns a JWT token.
-
Get All Users:
- Method: GET
- URL:
/api/users
- Description: Retrieves a list of all users (admin-only).
-
Get Single User:
- Method: GET
- URL:
/api/users/:id
- Description: Retrieves details of a specific user.
-
Update User:
- Method: PUT
- URL:
/api/users/:id
- Description: Updates user information.
-
Delete User:
- Method: DELETE
- URL:
/api/users/:id
- Description: Deletes a user (admin-only).
-
Get All Products:
- Method: GET
- URL:
/api/products
- Description: Retrieves all products.
-
Create Product:
- Method: POST
- URL:
/api/products
- Description: Creates a new product (accessible to sellers/admins).
-
Update Product:
- Method: PUT
- URL:
/api/products/:id
- Description: Updates product details.
-
Delete Product:
- Method: DELETE
- URL:
/api/products/:id
- Description: Deletes a product.
Note: For protected routes, include the following header:
Authorization: Bearer <your_jwt_token>
- Implement Caching: Add Redis for caching frequent queries.
- Automated Testing: Integrate unit and integration tests.
- Enhanced Error Handling: Improve logging and error responses.