A super simple Express + MongoDB REST API for managing inventory items.
Each item includes a name (item
) and a storage location (location
).
-
CRUD Endpoints
GET /inventory
— List all items with optional filtering, sorting, and pagination.GET /inventory/:id
— Retrieve a single item by ID.POST /inventory
— Create a new inventory item.PUT /inventory/:id
— Update an existing item.DELETE /inventory/:id
— Delete an item.
-
Input validation using a helper function (
pickInventory
). -
Case-insensitive searching via MongoDB collation.
-
Duplicate prevention on
item + location
pairs. -
Environment configuration via
.env
file.
git clone https://github.com/srcthird/cs499-inventory-api.git
cd inventory-api
npm install
Create a .env
file in the project root:
HOST=0.0.0.0
PORT=3000
MONGODB_URI=mongodb://<credentials>@localhost:27017/CS499
npm run dev
(or)
node dist/index.js
Create a new item
POST /inventory
Content-Type: application/json
{
"item": "Wrench",
"location": "Tool Room"
}
Response
{
"_id": "651abc1234...",
"item": "Wrench",
"location": "Tool Room"
}
GET /health
Response
{ "ok": true }