Skip to content

Latest commit

 

History

History
215 lines (170 loc) · 5.5 KB

File metadata and controls

215 lines (170 loc) · 5.5 KB

Book Review Application - Setup Instructions

Project Created Successfully! ✅

Your Book Review Application has been created and is ready to use. Here's everything you need to know:

What's Included

1. Complete Express.js Server (server.js)

  • RESTful API with all required endpoints
  • JWT and Session authentication
  • In-memory database for books and users
  • Error handling and validation

2. Authentication System

  • User registration with password hashing (bcryptjs)
  • JWT tokens (expire in 1 hour)
  • Session-based authentication
  • Login/Logout functionality

3. API Endpoints

Public Endpoints (No Authentication):

  • GET /api/v1/books - Get all books
  • GET /api/v1/books/isbn/:isbn - Get book by ISBN
  • GET /api/v1/books/author/:author - Get books by author
  • GET /api/v1/books/title/:title - Get books by title
  • GET /api/v1/reviews/isbn/:isbn - Get reviews for a book

Authentication Endpoints:

  • POST /api/v1/register - Register new user
  • POST /api/v1/login - Login (returns JWT token)
  • POST /api/v1/logout - Logout

Protected Endpoints (Requires Session):

  • POST /api/v1/reviews/isbn/:isbn - Add/Modify review
  • DELETE /api/v1/reviews/isbn/:isbn - Delete review

4. Pre-loaded Books

The application comes with 5 sample books:

  1. Clean Code - Robert C. Martin
  2. Design Patterns - Gang of Four
  3. Code Complete - Steve McConnell
  4. You Don't Know JS Yet - Kyle Simpson
  5. JavaScript: The Good Parts - Douglas Crockford

How to Run

1. Install Dependencies (if not done)

cd c:\Users\asmit\Desktop\book-review-app
npm install

2. Start the Server

npm start

or for development with auto-reload:

npm run dev

Server will run on: http://localhost:5000

3. Test with Postman

You can:

  • Import the BookReviewAPI.postman_collection.json file into Postman
  • OR manually test endpoints as shown in README.md

Testing Workflow (for Course Project)

Task 1: Get All Books

GET http://localhost:5000/api/v1/books

Expected: Returns array of 5 books

Task 2: Get Book by ISBN

GET http://localhost:5000/api/v1/books/isbn/978-0-13-110362-7

Expected: Returns Clean Code book details

Task 3: Get Books by Author

GET http://localhost:5000/api/v1/books/author/Robert%20C.%20Martin

Expected: Returns books by Robert C. Martin

Task 4: Get Books by Title

GET http://localhost:5000/api/v1/books/title/Clean%20Code

Expected: Returns books with "Clean Code" in title

Task 5: Get Book Reviews

GET http://localhost:5000/api/v1/reviews/isbn/978-0-13-110362-7

Expected: Returns reviews array (empty initially)

Task 6: Register User

POST http://localhost:5000/api/v1/register
Body: {
  "username": "testuser",
  "password": "test123",
  "email": "test@example.com"
}

Expected: 201 status with user created message

Task 7: Login

POST http://localhost:5000/api/v1/login
Body: {
  "username": "testuser",
  "password": "test123"
}

Expected: 200 status with JWT token

Task 8: Add/Modify Review (After Login)

POST http://localhost:5000/api/v1/reviews/isbn/978-0-13-110362-7
Headers: Cookie: connect.sid=<session_cookie>
Body: {
  "review": "Excellent book on clean code principles!"
}

Expected: 201 status with review added

Task 9: Delete Review (After Login)

DELETE http://localhost:5000/api/v1/reviews/isbn/978-0-13-110362-7
Headers: Cookie: connect.sid=<session_cookie>

Expected: 200 status with review deleted

Project Structure

book-review-app/
├── server.js                           # Main Express server
├── package.json                        # Dependencies
├── .env                                # Environment variables
├── .gitignore                          # Git ignore rules
├── README.md                           # Full documentation
├── SETUP.md                            # This file
└── BookReviewAPI.postman_collection.json  # Postman collection

Important Notes

  1. In-Memory Database: Data resets when server restarts

    • For production, use MongoDB, PostgreSQL, etc.
  2. Session Management: Cookies are stored in browser/Postman

    • Session expires after 60 minutes
  3. Password Security: Passwords are hashed using bcryptjs

    • Pre-configured test user available in code
  4. Authentication: Both JWT and Session auth are implemented

    • Review endpoints use Session auth (Postman cookies)

Git Repository Setup

To push to GitHub:

  1. Create a new repository on GitHub (e.g., book-review-app)
  2. In the project directory, run:
git remote add origin https://github.com/YOUR_USERNAME/book-review-app.git
git branch -M master
git push -u origin master

Environment Variables

Current .env file:

JWT_SECRET=your_jwt_secret_key_change_this_in_production
SESSION_SECRET=your_session_secret_key_change_this_in_production
PORT=5000

Change these values in production!

Troubleshooting

Port 5000 is Already in Use

Change PORT in .env and update Postman collection

Module Not Found Error

Run: npm install

Session Cookie Not Saving

In Postman:

  • Go to Settings > Cookies
  • Add cookies for localhost:5000

Next Steps

  1. ✅ Create GitHub repository
  2. ✅ Push code using git commands above
  3. ✅ Test all endpoints with Postman
  4. ✅ Screenshot each task for submission

Support

Refer to:

  • README.md - Full API documentation
  • server.js - Source code with comments
  • BookReviewAPI.postman_collection.json - API test collection