Node.js MongoDB
Clone the repository:
git clone https://github.com/vikasrana1998/library-backend.git
Navigate to the project directory:
cd library-backend-api
Install dependencies:
npm install
You can use the provided .env file.
Running the Server
Start MongoDB on the default port (27017).
Run the project:
node server.js
The server will start running on port 8000 by default.
Open Postman.
Make requests to the API endpoints using the base URL: https://localhost:8000/api/
Send requests using appropriate HTTP methods (GET, POST) and provide necessary request data.
Available Endpoints
POST /api/books: Add a new book to the library.
Sample Body:
{
"title": "Harry Potter 2",
"author": "J K Rowling",
"ISBN": "57807432735215",
"quantityAvailable": 10
}
GET /api/books: Retrieve a list of all available books.
GET /api/books/:id: Retrieve a specific book by its ID.
POST /api/users: Register a new user.
Sample Body:
{ "username": "Vikash Rana", "email": "vikas@test.com", "password": "123456" }
POST /api/users/login: Login with username/email and password.
Sample Body:
{ "email":"vikas@test.com", "password":"123456" }
POST /api/borrow/:bookId/:userId: Borrow a book.
POST /api/return/:bookId/:userId: Return a book.
GET /api/users/:userId/books: Retrieve books borrowed by a specific user.
Environment Variables
PORT: The port on which the server will run (default: 8000).
JWT_SECRET: Secret key for JWT token generation.
If you encounter any issues during setup or while running the server, Please ping me on my contact number.