Skip to content

HassanEssam0110/Task-3-Books-Management-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Books Management System

Objective

The Books Management System is a RESTful API built using Node.js, Express, and MongoDB. It provides user authentication and CRUD operations for managing books. Only authenticated users can perform book-related operations.

Features

  • User Registration & Login
  • Token-based Authentication using JWT
  • CRUD Operations for Books
  • Input Validation with Joi
  • Secure Password Handling with bcryptjs
  • Environment Variables with dotenv
  • Logging with Morgan
  • Error Handling & Data Integrity Checks

Technologies Used

  • Node.js
  • Express.js
  • MongoDB (Mongoose ODM)
  • JWT (jsonwebtoken)
  • bcryptjs
  • Joi (Input validation)
  • Morgan (Logging)
  • Compression (Performance optimization)

Installation & Setup

Prerequisites

Ensure you have the following installed:

Clone the Repository

git clone https://github.com/HassanEssam0110/Task-3-Books-Management-System.git
cd Task-3-Books-Management-System

Install Dependencies

npm install

Configure Environment Variables

Create a .env file in the project root and add the following:

# Server
PORT=3000
NODE_ENV="development"

# Database
MONGO_DB_URI="mongodb://127.0.0.1:27017/DB_books_management"

# JWT Authentication
JWT_SECRET="secret"
JWT_EXPIRES_IN="30d"
JWT_COOKIES_EXPIRES_IN=30

# Password Hashing
SALT_ROUNDS=10

Start the Server

Development Mode

npm run start:dev

Production Mode

npm run start:prod

API Endpoints

Authentication Routes

Register a New User

POST /api/v1/register

{
  "username": "user1",
  "password": "password123",
  "repeat_password": "password123"
}

Login a User

POST /api/v1/login

{
  "username": "user1",
  "password": "password123"
}

Book Management Routes (Authenticated Users Only)

Create a New Book

POST /api/v1/books

{
  "title": "The Great Gatsby",
  "author": "F. Scott Fitzgerald",
  "publishedDate": "1925-04-10"
}

Retrieve All Books

GET /api/v1/books

Retrieve a Specific Book by ID

GET /api/v1/books/:id

Update a Specific Book by ID

PUT /api/v1/books/:id

{
  "title": "The Great Gatsby",
  "author": "F. Scott Fitzgerald",
  "publishedDate": "1925-04-10"
}

Delete a Specific Book by ID soft delete

DELETE /api/v1/books/:id

Delete a Specific Book by ID delete from DB

DELETE /api/v1/books/:id?softDelete=false


About

REST API create a books management system with user registration, login, and CRUD operations for books only for authenticated users.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors