A Node.js/Express backend API for the Messconnect application - a hostel/mess management system that connects hosts with students for meal services.
This backend provides REST API endpoints for managing hosts, students, orders, and mess-related operations. It uses MongoDB for data persistence and includes features like user authentication, file uploads, and order management.
- Authentication: JWT-based authentication with password encryption (bcryptjs)
- User Management: Separate models for hosts and students
- Order Management: Track and manage student orders
- File Uploads: Support for document/image uploads via multer
- CORS Support: Configured for cross-origin requests
- Environment Configuration: Secure configuration using environment variables
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT, bcryptjs
- File Upload: multer
- Development: nodemon for auto-reload
├── db.js # MongoDB connection setup
├── server.js # Express server configuration
├── upload.js # File upload configuration
├── package.json # Project dependencies
├── models/
│ ├── Host.js # Host schema
│ ├── Stud.js # Student schema
│ └── Order.js # Order schema
├── routes/
│ ├── hosts.js # Host-related endpoints
│ └── students.js # Student-related endpoints
└── uploads/ # Directory for uploaded files
-
Clone the repository:
git clone <repository-url> cd messbackend_new
-
Install dependencies:
npm install
-
Create a
.envfile in the root directory with the following variables:PORT=3000 MONGO_URI=your_mongodb_connection_string CORS_ORIGIN=http://localhost:3000 JWT_SECRET=your_jwt_secret_key
npm run devor
npm startThe server will start on the port specified in .env (default: 3000).
node server.jsGET /host- Retrieve all hostsPOST /host- Create a new hostGET /host/:id- Get specific host detailsPUT /host/:id- Update host informationDELETE /host/:id- Delete a host
GET /student- Retrieve all studentsPOST /student- Register a new studentGET /student/:id- Get specific student detailsPUT /student/:id- Update student informationDELETE /student/:id- Delete a student
- Files are served from
/uploadsendpoint - Upload functionality is configured in
upload.js
- express - Web framework
- mongoose - MongoDB object modeling
- mongodb - MongoDB driver
- cors - Cross-Origin Resource Sharing middleware
- jwt - JSON Web Token for authentication
- bcryptjs - Password hashing
- multer - Middleware for handling file uploads
- dotenv - Environment variable management
- body-parser - Middleware for parsing request bodies
- nodemon - Development tool for auto-restarting
| Variable | Description | Required |
|---|---|---|
PORT |
Server port (default: 3000) | No |
MONGO_URI |
MongoDB connection string | Yes |
CORS_ORIGIN |
Allowed CORS origin | Yes |
JWT_SECRET |
Secret key for JWT signing | Yes |
- Create a feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
ISC
- Ensure MongoDB is running and accessible before starting the server
- Keep
.envfile secure and never commit it to version control - Use nodemon during development for automatic server restart on file changes