A Node.js backend service for managing product catalogs from CSV files with Express.js and SQLite.
- CSV Upload & Validation: Parse and validate CSV files with detailed error reporting
- Search & Filter: Advanced filtering by brand, color, and price range
- RESTful API: Well-structured endpoints with proper error handling
- SQLite Database: Lightweight, file-based database (no setup required)
- Data Validation: Comprehensive validation using Joi
- File Upload: Multer-based file handling with size limits
- Node.js 18+
- npm or yarn
- Install dependencies
npm install
A small Node.js backend for importing, validating and storing product data from CSV files. Built with Express.js and SQLite. The repository uses ESM modules ("type": "module" in package.json).
- CSV upload, streaming parse and per-row validation
- Product listing with pagination and search filters
- SQLite file-based storage (auto-created)
- Validation with Joi
- File uploads handled with Multer (5MB max)
- Node.js 18+ (or recent LTS)
- npm
- Install dependencies
cd backend
npm install- Create an environment file (optional)
On Unix/macOS:
cp env.example .envOn Windows (PowerShell):
Copy-Item env.example .envDefault values are:
PORT=8000
NODE_ENV=development
# Optionally override DB_PATH to change the sqlite file location
# DB_PATH=./database.sqlite- Start the development server
npm run dev- Production
npm startServer base URL: http://localhost:8000
API base path: http://localhost:8000/api
- POST /api/upload — upload a CSV file (multipart/form-data, field name
file, max 5MB) - GET /api/products — list products (supports
pageandlimitquery params) - GET /api/products/search — search with filters:
brand,color,minPrice,maxPrice
Example upload response (success):
{
"success": true,
"message": "CSV processed successfully",
"summary": { "totalRows": 20, "validRows": 18, "stored": 17, "failed": 3 }
}Required columns: sku, name, brand, mrp, price, quantity.
Optional columns: color, size.
Price must be ≤ MRP. Quantity must be an integer ≥ 0.
Example CSV header:
sku,name,brand,color,size,mrp,price,quantitybackend/
├── config/
│ └── database.js # sqlite config and pool-like wrapper
├── controllers/
│ ├── upload.controller.js # CSV upload handler
│ └── products.controller.js# Product listing/search handlers
├── middleware/
│ └── upload.middleware.js # multer upload config
├── models/
│ └── Product.model.js # Product DB methods
├── routes/
│ └── products.route.js # API routes registered under /api
├── utils/
│ ├── validation.js # Joi validation
│ └── csvParser.js # streaming CSV parser
├── uploads/ # temporary uploaded files (created at runtime)
├── database.sqlite # (created automatically)
├── .env # environment variables (local)
├── package.json
├── server.js # main server entry
└── README.md
Set in .env (or through your environment):
PORT=8000
NODE_ENV=development
# DB_PATH=./database.sqlite- If Nodemon reports module-not-found for
middlewarevsmiddlewares, check theroutesimports — the correct folder ismiddleware/(singular). - If the uploads directory is missing, it is created at runtime by the middleware, but ensure the backend process has write permissions.
- The backend uses ESM imports (files include the
.jsextension for local modules). Keeptype: "module"inbackend/package.json. - If you change file names, update imports to include the
.jsextension and correct relative paths.
MIT