Skip to content

Aditya7080-hub/streamoid_backend_assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

CSV Product Management - Backend API

A Node.js backend service for managing product catalogs from CSV files with Express.js and SQLite.

🚀 Features

  • 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

📋 Requirements

  • Node.js 18+
  • npm or yarn

🛠️ Quick Start

  1. Install dependencies
    npm install

CSV Product Management - Backend API

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).

Features

  • 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)

Requirements

  • Node.js 18+ (or recent LTS)
  • npm

Quick start (backend)

  1. Install dependencies
cd backend
npm install
  1. Create an environment file (optional)

On Unix/macOS:

cp env.example .env

On Windows (PowerShell):

Copy-Item env.example .env

Default values are:

PORT=8000
NODE_ENV=development
# Optionally override DB_PATH to change the sqlite file location
# DB_PATH=./database.sqlite
  1. Start the development server
npm run dev
  1. Production
npm start

Server base URL: http://localhost:8000

API base path: http://localhost:8000/api

API Endpoints

  • POST /api/upload — upload a CSV file (multipart/form-data, field name file, max 5MB)
  • GET /api/products — list products (supports page and limit query 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 }
}

CSV format

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,quantity

Project structure (backend)

backend/
├── 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

Environment variables

Set in .env (or through your environment):

PORT=8000
NODE_ENV=development
# DB_PATH=./database.sqlite

Troubleshooting

  • If Nodemon reports module-not-found for middleware vs middlewares, check the routes imports — the correct folder is middleware/ (singular).
  • If the uploads directory is missing, it is created at runtime by the middleware, but ensure the backend process has write permissions.

Notes

  • The backend uses ESM imports (files include the .js extension for local modules). Keep type: "module" in backend/package.json.
  • If you change file names, update imports to include the .js extension and correct relative paths.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published