A RESTful API for book management, built with Node.js, Express, and MongoDB.
- Node.js
- Express
- MongoDB with Mongoose
- Cors
- Morgan
- Dotenv
/book-management-api
│-- /config
│ ├── db.js # Database configuration
│-- /models
│ ├── Book.js # Book model
│-- /routes
│ ├── bookRoutes.js # Route definitions
│-- /controllers
│ ├── bookController.js # Request controllers
│-- /services
│ ├── bookService.js # Business logic
│-- server.js # Server initialization
│-- package.json # Project dependencies
│-- .env # Environment settings
- Install Node.js: Download Node.js
- Install MongoDB (locally or use MongoDB Atlas)
- Clone the repository:
git clone <REPO_URL> cd book-management-api
npm installCreate a .env file in the project's root and add:
MONGO_URI=mongodb://localhost:27017/bookstore
PORT=5000
npm startOr, for development with automatic restarts:
nodemon server.jsThe API exposes the following endpoints:
POST /api/booksJSON Body:
{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"publishedYear": 1925,
"genre": "Classic"
}GET /api/booksGET /api/books/:idPUT /api/books/:idJSON Body:
{
"title": "New Title"
}DELETE /api/books/:idYou can test the API using Postman, Insomnia, or curl commands in the terminal.
Example:
curl -X GET http://localhost:5000/api/booksThis project is open-source and free to use.
🚀 Developed with Node.js and MongoDB