RESTful API Backend berbasis Express.js dengan SQLite database. API ini menyediakan operasi CRUD untuk manajemen produk dengan validasi request, error handling terpusat, dan format response yang konsisten.
βββ src/
β βββ app.js # Main Express application
β βββ database.js # SQLite database setup
β βββ routes/
β β βββ products.js # Product CRUD routes
β βββ middleware/
β βββ validation.js # Request validation middleware
β βββ errorHandler.js # Centralized error handling
βββ data/
β βββ database.sqlite # SQLite database file
βββ package.json
GET /api/products- Get all products (supports query: category, search, limit, offset)GET /api/products/:id- Get product by IDPOST /api/products- Create new productPUT /api/products/:id- Update productDELETE /api/products/:id- Delete product
All responses follow consistent JSON format:
{
"success": true/false,
"message": "Description",
"data": {...}
}- Request validation middleware
- Centralized error handling
- Consistent JSON response format
- 404 handler for unknown routes
- Query filtering and pagination
npm startServer runs on port 5000.