Backend API for a Book Store system built with Node.js and Express.
Includes Prisma ORM with SQLite, Swagger docs, linting, formatting, and Docker support.
- Express server with basic folder structure
- Health check endpoint (
/health) - SQLite database (file-based)
- Prisma ORM integration
- Swagger API documentation (
/api-docs) - ESLint + Prettier setup
- Pre-commit hooks with Husky + lint-staged
- Nodemon for auto-reload
- Docker support
- Node.js
- Express
- Prisma ORM
- SQLite
- Swagger (swagger-ui-express, swagger-jsdoc)
- ESLint + Prettier
- Husky + lint-staged
- Docker
.
βββ src/
β βββ routes/
β βββ controllers/
β βββ services/
β βββ middlewares/
β βββ app.js
βββ prisma/
β βββ schema.prisma
βββ .husky/
βββ .eslintrc
βββ .prettierrc
βββ Dockerfile
βββ package.json
βββ README.md
npm installnpm run dev- Server runs on:
http://localhost:3000 - Health check:
GET /health - Swagger docs:
http://localhost:3000/api-docs
npx prisma initnpm run prisma:migratenpm run prisma:generatemodel Book {
id Int @id @default(autoincrement())
name String
author String
price Float
publisher String?
}npm run lintnpm run lint:fixnpm run format- ESLint runs on staged files
- Prettier formats staged files
- Commit blocked on errors
docker build -t bookstore-api .docker run -p 3000:3000 bookstore-api"scripts": {
"start": "node src/server.js",
"dev": "nodemon src/server.js",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"prisma:migrate": "npx prisma migrate dev",
"prisma:generate": "npx prisma generate"
}Create a .env file:
DATABASE_URL="file:./dev.db"
PORT=3000
- Core setup complete
- Database connected
- Tooling configured
- Dockerized
POST /books ""Endpoint**
Description: Creates a new book with multiple authors and stores it in the database.
{
"name": "Atomic Habits",
"authors": ["Zain", "Chris"],
"price": 100,
"publisher": "Humdard Publisher"
}nameβ required (string)authorsβ required (array of strings)priceβ required (number, must be β₯ 0)publisherβ optional (string)
{
"id": 1,
"name": "Atomic Habits",
"price": 100,
"publisher": "Humdard Publisher",
"authors": [{ "name": "Zain" }, { "name": "Chris" }]
}{
"error": "Validation failed",
"details": "Invalid input data"
}You can test the API using:
- Swagger UI β
http://localhost:3000/api-docs - Postman / Thunder Client
- Ensure
express.json()middleware is enabled - Request body must match validation schema