(cursor project) A RESTful API for file storage built with Express.js. This API allows you to upload, download, list, and delete files.
- File upload with metadata storage
- File download by ID
- List all uploaded files
- Delete files
- CORS support
- Error handling
- File size limit (10MB)
- Install dependencies:
pnpm install- Create a
.envfile in the root directory (already done with basic configuration):
PORT=3000
NODE_ENV=developmentDevelopment mode with hot-reload:
pnpm devProduction mode:
pnpm start- POST
/api/files/upload - Body:
multipart/form-data - Field:
file
- GET
/api/files/download/:id - Returns the file as a download
- GET
/api/files/list - Returns a list of all uploaded files with metadata
- DELETE
/api/files/:id - Deletes both the file and its metadata
src/index.js- Main application entry pointsrc/routes/- API routessrc/controllers/- Request handlerssrc/middleware/- Custom middlewareuploads/- File storage directory.env- Environment variablespackage.json- Project configuration and dependencies
Files are stored in the uploads directory with the following structure:
- Actual files are stored with unique names
- Metadata is stored in JSON files with the file ID as the filename