This is a REST API for managing a bookstore, built with Express.js and MongoDB. It provides CRUD operations for books and user authentication.
- Install Node.js and npm.
- Clone this repository.
- Navigate to the project directory.
- Run
npm install
to install dependencies. - Set up your
.env
file with MongoDB URI and JWT secrets.
To start the server, use the command:
npm start
The server will start listening on port 8080
by default.
npm install express
npm install mongoose
npm install dotenv
npm install jsonwebtoken
npm install bcryptjs
npm install multer
npm install cloudinary
POST /api/auth/register
- Register a new user.POST /api/auth/login
- Login and get a JWT token.
GET /api/books
- Get all books.GET /api/books/:id
- Get a book by ID.POST /api/books
- Create a new book (Admin only).PUT /api/books/:id
- Update a book by ID (Admin only).DELETE /api/books/:id
- Delete a book by ID (Admin only).
GET /api/users
- Get all users.DELETE /api/users/:id
- Delete a user by ID.
POST /api/orders
- Create a new order.GET /api/orders/:userId
- Get orders for a user.PUT /api/orders/:id
- Update order status (Admin only).
- Book titles must be at least 3 characters long.
- Users must provide a valid email and password during registration.
Use Postman or a similar tool to test the API.
{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"year": 1925,
"price": 10.99
}
Contributions are welcome! Submit bug reports or feature requests via GitHub issues.
This project is licensed under the MIT License - see the LICENSE file for details.