A backend-focused project for uploading, downloading, and storing files. Built using Node.js, Express, MongoDB and JWT Authentication.
- User authentication using JWT (cookies)
- Secure file upload using multer
- Stream-based file download
- Authorization checks per file owner
- MongoDB for metadata storage
- Node.js
- Express.js
- MongoDB + Mongoose
- JWT (jsonwebtoken)
- Multer (file uploads)
- bcrypt (password hashing)
- cookie-parser
- dotenv
Create a .env file in the root directory of the project.
PORT=3000
NODE_ENV=development
MONGO_URI=mongodb://127.0.0.1:27017/boogledrive
JWT_SECRET=your_jwt_secret
SUPABASE_URL=your_project_url
SUPABASE_SERVICE_KEY=your_service_key
SUPABASE_BUCKET=uploads- Clone the repository
git clone https://github.com/aryansinha1908/BoogleDrive.git
cd BoogleDrive- Install Dependencies
npm install- Start MongoDB
**NOTE: ** Make sure MongoDB is running locally
mongod- Start the server
npm startServer will run on:
http://localhost:3000
| Situation | Status Code |
|---|---|
| Not logged in | 401 Unauthorized |
| File not found | 404 Not Found |
| Accessing someone else's file | 403 Forbidden |
This project can be fully tested using Postman.
Method: POST
URL: http://localhost:3000/user/register
Body (JSON):
{
"username": "testuser",
"email": "test@example.com",
"password": "password123"
}Method: POST
URL: http://localhost:3000/user/login
Body (JSON):
{
"username": "testuser",
"password": "password123"
}On successful login:
- Response: Logged in
- A cookie named
tokenis set automatically
Method: POST
URL: http://localhost:3000/user/logout
On successful logout:
- Response: Logged out
- Token will be removed from cookies
Method: POST
URL: http://localhost:3000/files/upload
Steps in Postman:
- Go to the Body tab
- Select form-data
- Add a field:
- Key:
file - Type:
File - Value: Select any file from local machine
- Key:
Without errors,
- File is stored in supabase storage
- File's metadata is stored in MongoDB
Method: GET
URL: http://localhost:3000/files/download/<fileId>
If authorized:
- A supabase signed url will be generated with time limit of 60 minutes
- The file will be downloaded directly
- Only the Owner of the file can download it.
Method: DELETE
URL: http://localhost:3000/files/delete/<fileId>
If file exists and the user is authorized:
- Response: Deleted
- The file is removed from the supabase storage
- The file's metadata is deleted from MongoDB
Method: GET
URL: http://localhost:3000/files/my-files
All the files uploaded by the user will be sent in json format.
This project uses JWT based authentication stored in HTTP-only cookies.
- A registered user logs in using username and password.
- Backend verifies credentials using bcrypt.
- Backend generates a JWT token containing:
- userId
- username
- JWT is stored in an HTTP-only cookie.
- Protected routes use a middleware to verify the JWT.
To prevent tokens from being valid forever, both the JWT and cookie are configured to expire.
- The token created using JWT expires in 7 days.
- The cookie is deleted in 7 days.
Aryan Sinha (aryansinha1908)