A secure file upload service in Node.js that stores file metadata in a database, runs background processing tasks, and tracks the status of those tasks.
- Node.js ≥ 18
- PostgreSQL
- Redis
- Yarn or npm
-
Clone the repository:
git clone https://github.com/Vedant005/File_secure.git cd file_secure -
Install Dependencies
npm install -
Create and configure .env
PORT=3000
JWT_SECRET=your_jwt_secret
DATABASE_URL=postgresql://user:password@localhost:5432/upload_service
REDIS_PORT=6379
- Generate and migrate Prisma schema:
npx prisma migrate dev --name init
- Run the app and worker
- Server:
npm run dev
- Worker:
npm run worker
- Authentication
POST /auth/login
{
"email": "testing@dmail.com",
"password": "testingPass"
}- Upload File POST /upload
Headers:
Authorization: Bearer <token>
Content-Type: multipart/form-data
FormData:
- file: any file format (required)
- title: string (optional)
- description : string (optional)
Response:
{
"id": 1,
"status": "uploaded"
}- Get File Status
GET /files/:id
Authorization: Bearer <token>
Response:
{
"id": 1,
"title": "My File",
"description": "Some papers",
"original_filename": "example.txt",
"status": "processed",
"extracted_data": "abc123filehash...",
"uploaded_at": "2025-05-31T08:00:00.000Z"
}A rough API Flow :
-
POST /auth/login → Receive JWT
-
POST /upload (with file + metadata) → Returns file ID + status uploaded
-
Background job picks up and processes file → Updates DB status to processed
-
GET /files/:id → Returns file info, status, and extracted result