A comprehensive Node.js/Express application for managing book reviews with JWT and Session authentication.
- Book Management: View books by ISBN, Author, Title
- User Authentication: Register, Login with JWT and Session support
- Book Reviews: Add, Modify, Delete reviews (authenticated users only)
- RESTful API: Clean and organized API endpoints
- Clone the repository:
git clone <your-repo-url>
cd book-review-app- Install dependencies:
npm install- Create a
.envfile in the root directory:
JWT_SECRET=your_jwt_secret_key
SESSION_SECRET=your_session_secret_key
PORT=5000
- Start the server:
npm startFor development with auto-reload:
npm run devPOST /api/v1/register
Content-Type: application/json
{
"username": "newuser",
"password": "password123",
"email": "user@example.com"
}
POST /api/v1/login
Content-Type: application/json
{
"username": "newuser",
"password": "password123"
}
Returns: JWT token and user information
POST /api/v1/logout
GET /api/v1/books
GET /api/v1/books/isbn/:isbn
Example:
GET /api/v1/books/isbn/978-0-13-110362-7
GET /api/v1/books/author/:author
Example:
GET /api/v1/books/author/Robert%20C.%20Martin
GET /api/v1/books/title/:title
Example:
GET /api/v1/books/title/Clean%20Code
GET /api/v1/reviews/isbn/:isbn
Example:
GET /api/v1/reviews/isbn/978-0-13-110362-7
POST /api/v1/reviews/isbn/:isbn
Content-Type: application/json
Cookie: connect.sid=<session_cookie>
{
"review": "Great book! Very informative."
}
DELETE /api/v1/reviews/isbn/:isbn
Cookie: connect.sid=<session_cookie>
The application comes with 5 pre-loaded books:
- Clean Code by Robert C. Martin (ISBN: 978-0-13-110362-7)
- Design Patterns by Gang of Four (ISBN: 978-0-201-63361-0)
- Code Complete by Steve McConnell (ISBN: 978-0-201-71088-8)
- You Don't Know JS Yet by Kyle Simpson (ISBN: 978-1-617-29476-5)
- JavaScript: The Good Parts by Douglas Crockford (ISBN: 978-0-596-00712-6)
- Start the server:
npm start - Open Postman
- Test endpoints following the examples above
- For authenticated endpoints:
- First, call POST /api/v1/login
- Postman will automatically save session cookies
- Use the saved session to make authenticated requests
The application supports two authentication methods:
-
JWT (JSON Web Tokens)
- Include token in Authorization header:
Authorization: <token> - Token expires in 1 hour
- Include token in Authorization header:
-
Session-based
- Session cookie is automatically stored
- Session expires in 60 minutes
- Perfect for web applications
book-review-app/
├── server.js # Main Express application
├── package.json # Project dependencies
├── .env # Environment variables
├── .gitignore # Git ignore rules
└── README.md # Documentation
- Express.js - Web server framework
- jsonwebtoken - JWT implementation
- bcryptjs - Password hashing
- express-session - Session management
- axios - HTTP client (for external API calls)
- body-parser - Request body parsing
- dotenv - Environment variable management
- This is a demonstration/educational project
- User data and reviews are stored in memory (not persistent)
- For production, implement a proper database (MongoDB, PostgreSQL, etc.)
- Change the JWT_SECRET and SESSION_SECRET in production
ISC