A RESTful API for managing student records built with Node.js, Express, and MongoDB.
This application provides a backend system for managing student records through a RESTful API. It allows users to create, read, update, and delete student information using standard HTTP methods.
- CRUD Operations: Complete set of Create, Read, Update, and Delete operations for student records
- RESTful API: Follows REST architectural style with standard HTTP methods
- MongoDB Integration: Uses MongoDB Atlas for data persistence
- Data Validation: Validates student data before saving to the database
- Error Handling: Proper error handling with appropriate status codes
- Node.js: JavaScript runtime environment
- Express.js: Web application framework for Node.js
- MongoDB: NoSQL database
- Mongoose: MongoDB object modeling tool
- dotenv: Environment variables management
student-records-api/
├── controllers/ # Request handlers
│ └── studentController.js
├── models/ # Database models
│ └── Student.js
├── routes/ # API routes
│ └── studentRoutes.js
├── .env # Environment variables (not included in repository)
├── .gitignore # Git ignore file
├── dbConfig.js # Database configuration
├── package.json # Project dependencies
└── server.js # Application entry point
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
| GET | /students | Retrieves all students | - | Array of student objects |
| GET | /students/:id | Retrieves a specific student | - | Student object |
| POST | /students | Creates a new student | Student details (firstName, lastName, etc.) | Created student object |
| PUT | /students/:id | Updates a student | Updated student details | Updated student object |
| DELETE | /students/:id | Deletes a student | - | Success message |
-
Clone the repository:
git clone <repository-url> cd student-records-api -
Install dependencies:
npm install -
Create a
.envfile in the project root with the following variables:MONGODB_URI=your_mongodb_connection_string PORT=3000 -
Start the server:
npm run dev
POST http://localhost:3000/students
Content-Type: application/json
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"course": "Computer Science"
}
GET http://localhost:3000/students
GET http://localhost:3000/students/60d21b4667d0d8992e610c85
PUT http://localhost:3000/students/60d21b4667d0d8992e610c85
Content-Type: application/json
{
"firstName": "John",
"lastName": "Smith",
"email": "john.smith@example.com",
"course": "Data Science"
}
DELETE http://localhost:3000/students/60d21b4667d0d8992e610c85
To start the server in development mode with automatic restart on file changes:
npm run dev
To start the server in production mode:
npm start
The API returns appropriate HTTP status codes:
- 200: Success
- 201: Resource created
- 400: Bad request
- 404: Resource not found
- 500: Server error
- Authentication and authorization
- Pagination for GET requests
- Advanced filtering and sorting
- Input sanitization
- CORS configuration
- Rate limiting
This project is licensed under the MIT License.