A RESTful API for managing a School Library System built with Node.js, Express.js, and MongoDB. This API handles Authors, Books, Students, Library Attendants, and Book Borrowing & Returns.
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB (Mongoose ODM)
- Dev Tools: Nodemon, dotenv
-
Clone the repository
git clone https://github.com/Kabazbay/libsystem.git cd libsystem -
Install dependencies
npm install
-
Create a
.envfile in the root directorymongoDB=mongodb://localhost:27017/libraryDB -
Start MongoDB (if not already running)
mongod
-
Start the server
npm run dev
-
The API will be running at
http://localhost:3000
/School Library Management API
/models
author.js
book.js
student.js
attendant.js
/controllers
authorController.js
bookController.js
studentController.js
attendantController.js
/routes
authorRoutes.js
bookRoutes.js
studentRoutes.js
attendantRoutes.js
/config
database.js
server.js
Base URL: http://localhost:3000
- POST
/authors - Body:
{ "name": "Chinua Achebe", "bio": "Nigerian novelist and poet" } - Response:
200— Created author object
- GET
/authors - Response:
200— Array of all authors
- GET
/authors/:id - Response:
200— Single author object
- PUT
/authors/:id - Body:
{ "name": "Updated Name", "bio": "Updated bio" } - Response:
200— Updated author object
- DELETE
/authors/:id - Response:
200— Deleted author object
- POST
/books - Body:
{ "title": "Things Fall Apart", "isbn": "978-0-385-47454-2", "authors": ["<author_id>"] } - Response:
200— Created book object - Error:
400— If ISBN already exists
- GET
/books - Response:
200— Array of all books (authors populated)
- GET
/books/:id - Response:
200— Single book object with populatedauthors,borrowedBy, andissuedBy
- PUT
/books/:id - Body:
{ "title": "Updated Title" } - Response:
200— Updated book object
- DELETE
/books/:id - Response:
200— Deleted book object
- POST
/students - Body:
{ "name": "John Doe", "email": "john@school.com", "studentID": "STU001" } - Response:
200— Created student object
- GET
/students - Response:
200— Array of all students
- GET
/students/:id - Response:
200— Single student object
- POST
/attendants - Body:
{ "name": "Jane Smith", "staffID": "STAFF001" } - Response:
200— Created attendant object
- GET
/attendants - Response:
200— Array of all attendants
- POST
/books/:id/borrow - Body:
{ "studentId": "<student_id>", "attendantId": "<attendant_id>", "returnDate": "2026-04-01" } - Rules:
- Book must have status
"IN" - Student and Attendant must exist
- Book must have status
- Response:
200—{ "message": "Book borrowed successfully" } - Error:
400— If book is already borrowed - Error:
404— If student, attendant, or book not found
- POST
/books/:id/return - Rules:
- Book must have status
"OUT" - After return: status →
"IN", clearsborrowedBy,issuedBy,returnDate
- Book must have status
- Response:
200— Updated book object - Error:
404— If book not found
| Field | Type | Required |
|---|---|---|
| name | String | Yes |
| bio | String | No |
| createdAt | Date | Auto |
| Field | Type | Required | Notes |
|---|---|---|---|
| title | String | Yes | |
| isbn | String | Yes | Unique |
| authors | [ObjectId] | Yes | References Author |
| status | String | No | "IN" or "OUT", default: "IN" |
| borrowedBy | ObjectId | No | References Student |
| issuedBy | ObjectId | No | References Attendant |
| returnDate | Date | No | |
| createdAt | Date | Auto |
| Field | Type | Required | Notes |
|---|---|---|---|
| name | String | Yes | |
| String | Yes | Unique | |
| studentID | String | Yes | Unique |
| createdAt | Date | Auto |
| Field | Type | Required | Notes |
|---|---|---|---|
| name | String | Yes | |
| staffID | String | Yes | Unique |
| createdAt | Date | Auto |