https://github.com/ndmen/booklibrary
RESTful API for managing a book library with roles and error handling. The API built using Node.js, Express, and Sequelize, providing different access levels for users based on their roles, and including error handling.
https://github.com/ndmen/booklibrary
express javascript nodejs sequelize swagger
Last synced: about 1 month ago
JSON representation
RESTful API for managing a book library with roles and error handling. The API built using Node.js, Express, and Sequelize, providing different access levels for users based on their roles, and including error handling.
- Host: GitHub
- URL: https://github.com/ndmen/booklibrary
- Owner: ndmen
- Created: 2024-01-23T19:26:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-25T10:39:25.000Z (over 2 years ago)
- Last Synced: 2025-03-14T10:21:21.494Z (over 1 year ago)
- Topics: express, javascript, nodejs, sequelize, swagger
- Language: JavaScript
- Homepage: https://ibb.co/tZfDtnM
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Book Library
This project involves developing a RESTful API for managing a book library with roles and error handling. The API built using Node.js, Express, and Sequelize, providing different access levels for users based on their roles, and including error handling.
Data Models:
Book: Fields include id, title, author, year, and genre.
User: Fields include id, username, password, and roleId.
Role: Fields include id and name (e.g., 'user', 'admin').
Authentication and Authorization:
Implementation of authentication using JWT (JSON Web Tokens).
Implementation of middleware for authorization, determining access based on user roles.
Admin-specific Rights:
Only users with the 'admin' role can edit book information (PATCH, DELETE on /books/:id).
CRUD Operations for Books:
All users can view books.
Adding, editing, and deleting books is restricted to admins.
User Management:
CRUD operations for users and roles, accessible only to admins.
Error Handling Middleware:
Implementation of middleware for error handling and logging.
Properly returning errors to clients (e.g., 404 for nonexistent resources, 403 for forbidden access).
Documentation:
Preparation of API documentation using Swagger.

## Getting Started
These instructions will help you set up and run the project on your local machine.
### Prerequisites
- Node.js 16+ installed
- npm installed
- PostgreSQL 12+ installed
### Installation
1. Clone the repository:
```bash
git clone https://github.com/ndmen/booklibrary.git
```
2. Navigate to the project folder:
```bash
cd booklibrary
```
3. Install dependencies:
```bash
npm install
```
4. Set up your environment variables:
Update necessary environment variables for database connection in the file /confiig/config.json
5. Run migrations
```bash
npm run migrate:run
```
6. Run seeds (Roles)
```bash
npm run seed:run
```
7. Run the project:
```bash
npm start
```
The server should now be running on http://localhost:3000. Swagger documtation can see http://localhost:3000/swagger.
## Contributing
If you'd like to contribute, please fork the repository and create a pull request.
## License
This project is licensed under the MIT License.