A robust, scalable backend service for secure file management, now built with Express (Node.js), PostgreSQL, Amazon S3, and Redis. The REST API preserves the original logic (authentication, file uploads, metadata, caching) while moving from FastAPI/Python to a JavaScript stack.
-
User Authentication: Secure registration and login using JWT tokens stored in HTTP-only cookies.
-
File Upload & Storage: Users can upload multiple files, which are stored in Amazon S3. Metadata is managed in a PostgreSQL database.
-
File Retrieval & Search: Retrieve and search files by filename, extension, or content type. Generates presigned S3 URLs for secure file access.
-
File Deletion: Users can delete individual files or all their files. Deletion is handled both in the database and in S3.
-
Caching with Redis: File listing and search results are cached in Redis for fast repeated access and reduced database load.
-
Scalable Microservices: All services are containerized with Docker for independent deployment and scalability.
- Backend: Express (Node.js)
- Database: PostgreSQL (pg client)
- Cloud Storage: Amazon S3 (AWS SDK v3)
- Authentication: JWT (jsonwebtoken, bcrypt)
- Caching: Redis
- Environment Management: dotenv
file_backend/
├── server.js # Express app entry point and route mounting
├── db.js # PostgreSQL pool setup
├── redisClient.js # Redis client factory
├── s3.js # S3 helpers (upload, delete, presign)
├── middleware/
│ └── auth.js # Cookie-based JWT auth middleware
├── routes/
│ ├── auth.js # User registration, login, logout endpoints
│ └── user.js # File upload, retrieval, search, and deletion endpoints
├── logger.js # Winston-based logger
├── package.json # Node.js dependencies and scripts
└── (legacy python files retained for reference)
- Users register and log in via
/auth/registerand/auth/login. - Passwords are securely hashed.
- JWT tokens are issued and stored in cookies for session management.
- Upload:
Users upload files via
/user/upload. Files are streamed to S3, and metadata is saved in PostgreSQL. - List/Search:
/user/filesreturns all files or filtered results. Results are cached in Redis for performance. - Delete:
/user/filesdeletes all user files (from both S3 and the database). Individual file deletion can be easily extended. - Presigned URLs: Secure, time-limited S3 URLs are generated for file access.
- Redis is used to cache file listings and search results, reducing database and S3 calls.
- Each microservice (API, database, etc.) can be containerized and deployed independently for scalability and maintainability.
IMPORTANT: Follow these setup steps carefully! If you are unsure about any step, follow the detailed instructions below. If you already know what you are doing, you may proceed quickly.
-
Clone the repository:
git clone https://github.com/primegen-git/file-sharing-management-api cd file-sharing-management-api -
Install and Configure PostgreSQL:
- Install PostgreSQL on your system or use Docker.
- Log in as the root user and create a database named
file-share(or use your own name but match in .env). - Default connection info:
- User:
postgres - Password:
your_password_here - Port:
5432 - Host:
localhost(or service name if using Docker) - Database:
file-share
- User:
- Use these same values in your
.envfile as shown in.env.example.
-
Install and Run Redis:
- Install Redis on your system or run with Docker.
- Start Redis with a password (recommended):
redis-server --requirepass your_redis_password
- Make sure the same
REDIS_PASSWORDis set in your.envfile (see.env.example).
-
Set up AWS S3 Bucket & Credentials:
- Create an S3 bucket on AWS.
- Create an IAM user with programmatic access and attach a policy allowing access to your bucket.
- Note the following details and add them to your
.envfile:AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGIONS3_BUCKET_NAME
- See
.env.examplefor all needed variables.
-
Set up environment variables:
- Copy the example env file:
cp .env.example .env
- Edit
.envand fill in all required secrets and settings.
- Copy the example env file:
-
Install Node dependencies:
npm install
-
Run the application:
npm run dev # reload with nodemon # or npm start # plain node
The existing
docker-compose.ymlwas built for the legacy FastAPI setup. Update it to point toserver.jsif you plan to containerize the new Express server.
## API Endpoints Overview
- `POST /auth/register` — Register a new user
- `POST /auth/login` — Login and receive JWT token in cookie
- `POST /auth/logout` — Logout and clear session
- `POST /user/upload` — Upload one or more files
- `GET /user/files` — List/search user files (with Redis caching)
- `DELETE /user/files` — Delete all user files
- `DELETE /user/` — Delete user account and all associated files