A Node.js Express server that serves category icons and provides API endpoints for the BlinkIt Clone frontend.
- In-memory category storage: All category icons are stored in a Map for fast access
- RESTful API endpoints: Get all categories, specific categories, and serve images
- Static file serving: Serves HTML, CSS, and images
- Error handling: Proper error responses for missing resources
- Install Node.js dependencies:
npm install
npm run dev
npm start
The server will start on http://localhost:3000
GET /api/categories
Response:
{
"success": true,
"data": [
{
"id": "paan",
"name": "Paan Corner",
"imageName": "category-paan.avif",
"alt": "Paan Corner"
},
// ... more categories
],
"count": 10
}
GET /api/categories/:id
Example: GET /api/categories/paan
Response:
{
"success": true,
"data": {
"id": "paan",
"name": "Paan Corner",
"imageName": "category-paan.avif",
"alt": "Paan Corner"
}
}
GET /api/categories/:id/image
Example: GET /api/categories/paan/image
Returns the actual image file for the category.
POST /api/categories
Request Body:
{
"id": "new-category",
"name": "New Category Name",
"imageName": "category-new.avif",
"alt": "New Category Alt Text"
}
The server includes the following categories:
- paan: Paan Corner
- dairy: Dairy, Bread & Eggs
- fruits: Fruits & Vegetables
- drinks: Cold Drinks & Juices
- snacks: Snacks & Munchies
- breakfast: Breakfast & Instant Food
- sweet: Sweet Tooth
- bakery: Bakery & Biscuits
- tea: Tea, Coffee & Health Drink
- grains: Atta, Rice & Dal
BlinkIt Clone/
├── server.js # Main server file
├── package.json # Node.js dependencies
├── index.html # Frontend HTML
├── styles.css # Frontend styles
├── images/ # Category images
│ ├── category-paan.avif
│ ├── category-dairy.avif
│ └── ... (other images)
└── README.md # This file
# Get all categories
curl http://localhost:3000/api/categories
# Get specific category
curl http://localhost:3000/api/categories/paan
# Get category image
curl http://localhost:3000/api/categories/paan/image -o paan-image.avif
// Get all categories
fetch('/api/categories')
.then(response => response.json())
.then(data => console.log(data));
// Get specific category
fetch('/api/categories/paan')
.then(response => response.json())
.then(data => console.log(data));
The API returns proper HTTP status codes and error messages:
200
: Success400
: Bad Request (missing required fields)404
: Not Found (category or image doesn't exist)409
: Conflict (category already exists)500
: Internal Server Error
To modify the categories, edit the categoryIcons
Map in server.js
. The structure is:
const categoryIcons = new Map([
['category-id', {
id: 'category-id',
name: 'Category Display Name',
imageName: 'category-image.avif',
alt: 'Alt text for accessibility'
}]
]);