This is a Node.js + Express web application for managing books and user authentication. It supports user registration, login/logout, book CRUD operations, and image uploads.
npm install
cp .env.example .env
npm start
- Backend: Node.js, Express.js
- Frontend: EJS Templates, SCSS, FontAwesome
- Database: MongoDB (via Mongoose)
- Authentication: JWT, Session-based
- File Upload: Multer (for book images)
- Security: Origin-based CORS validation
- Register and Login with bcrypt-hashed passwords
- JWT-protected routes
- View paginated list of books
- View book details
- Create new book
- Edit existing book
- Delete book
- Upload cover image
- Responsive UI
- Error and loading state handling
- Easy to extend for unit testing
| Route | Method | Description |
|---|---|---|
/ |
GET | Show paginated book list |
/view/:id |
GET | View book detail |
/create |
GET | Render create book form |
/update/:id |
GET | Render edit book form |
/api/create |
POST | Create book (with image) |
/api/update/:id |
POST | Update book info |
/api/delete-book/:id |
GET | Delete book |
| Route | Method | Description |
|---|---|---|
/register |
GET | Render register form |
/api/register |
POST | Register new user |
/login |
GET | Render login form |
/api/login |
POST | Authenticate user |
/api/logout |
GET | Destroy session and logout |
| Method | Path | Description | Auth Required | Request Params / Body |
|---|---|---|---|---|
| POST | /api/register | Register a new user | No | Body (JSON):email, password, name |
| POST | /api/login | Authenticate user and start session | No | Body (JSON):email, password |
| POST | /api/create | Create a new book with image upload | Yes (JWT) | Form Data (multipart/form-data):title, author, published_year, genre, image |
| POST | /api/update/:id | Update book details by ID | Yes (JWT) | URL Param: idBody (JSON): title, author, published_year, genre |
| GET | /api/delete-book/:id | Delete book by ID | Yes (JWT) | URL Param: id |
- Unit tests with Mocha, Chai, Supertest
- Code coverage reports
- Expired token handling
- Role-based access control