A RESTful API built with Node.js, Express, TypeScript, and SQLite for managing a collection of books. It supports CRUD operations and includes authentication.
- Add a new book 📖
- Retrieve all books 📚
- Get details of a specific book 🔍
- Update book details ✏️
- Delete a book 🗑️
- Basic JWT authentication 🔐
- Node.js + Express.js
- TypeScript
- SQLite (for lightweight database storage)
- JWT Authentication
- Nodemon (for auto-restart during development)
Make sure you have the following installed:
git clone https://github.com/your-username/backend-assignment.git
cd backend-assignmentnpm install- Create a
.envfile in the project root. - Add the following environment variables:
PORT=5000
JWT_SECRET=your_secret_key_here
npm run devnpm run build
npm start| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/books |
Add a new book | ✅ Yes |
GET |
/api/books |
Get all books | ❌ No |
GET |
/api/books/:id |
Get book details | ❌ No |
PUT |
/api/books/:id |
Update book | ✅ Yes |
DELETE |
/api/books/:id |
Delete book | ✅ Yes |
🔐 Protected routes require a Basic Auth Key in the Authorization header.
backend-assignment/
│── src/
│ ├── config/ # Database configuration
│ ├── controllers/ # Business logic (API handlers)
│ ├── middlewares/ # Authentication middleware
│ ├── models/ # Database models
│ ├── routes/ # Express routes
│ ├── services/ # Service layer (business logic)
│ ├── utils/ # Utility functions
│ ├── server.ts # Server entry point
│── .env # Environment variables
│── package.json # Project dependencies & scripts
│── README.md # Project documentation
This project is licensed under the MIT License.