DevTinder is a MERN stack web application designed to help developers connect and collaborate, similar to Tinder but specifically for developers. Users can create profiles, explore other developers, send connection requests, and manage their matches.
This repository contains the backend of DevTinder, built with Node.js, Express, and MongoDB, following a microservices architecture for scalability.
β οΈ Note: The backend is fully functional and ready for further scaling and optimizations.
- Backend Framework: Node.js + Express.js
- Database: MongoDB + Mongoose
- Authentication: JWT (JSON Web Tokens) + Cookies
- Encryption: bcryptjs for password hashing
- API Testing: Postman
- Environment Variables Management: dotenv
- Package Manager: npm
β
User Signup, Login, and Logout
β
JWT-based authentication with secure cookies
β
Password encryption using bcryptjs
β
Authentication middleware to protect routes
β
View user profile
β
Edit profile details (restricted fields for security)
β
Update password with validation
β
Send connection requests (Interested
or Ignored
)
β
Accept or reject received requests
β
Prevent duplicate requests using MongoDB validation
β
Prevent self-requests using Mongoose .pre
middleware
β Fetch suggested developers while excluding:
- Logged-in user
- Existing connections
- Ignored users
- Users with pending requests
β Implemented pagination usingskip
&limit
β Optimized query using MongoDB $nin and $ne operators
β User Schema:
- Sanitized input fields (
trim
,lowercase
, validation) - Unique constraints on email and username
β ConnectionRequest Schema:
fromUserId
,toUserId
,status
with enum validation- Indexed fields for optimized queries
- Prevents multiple requests between the same users
β Indexes & Compound Indexes:
- Used
index: true
for faster queries - Implemented compound indexes to optimize search
β
Authentication Middleware: Protects private routes
β
Error Handling Middleware: Centralized error response
β
Mongoose .pre
Middleware: Prevents self-requests
β
Modular route organization for maintainability
β
APIs structured into separate routers (auth
, profile
, connections
, users
)
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST | /auth/signup |
Register a new user | β |
POST | /auth/login |
Authenticate user & issue JWT | β |
POST | /auth/logout |
Logout user by clearing JWT cookie | β |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET | /profile/view |
Get logged-in user profile | β |
PATCH | /profile/edit |
Update allowed profile fields | β |
PATCH | /profile/password |
Update user password | β |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
POST | /request/send/:status/:toUserId |
Send a connection request (Interested/Ignored) | β |
POST | /request/review/:status/:requestId |
Accept/Reject a request | β |
GET | /user/requests/received |
Fetch pending connection requests | β |
GET | /user/connections |
Fetch accepted connections | β |
Method | Endpoint | Description | Auth Required |
---|---|---|---|
GET | /user/feed?page=1&limit=10 |
Get suggested developer profiles with pagination | β |
git clone https://github.com/harshmann10/DevTinder-backend.git
cd DevTinder-backend
Create a .env
file and add:
DATABASE_URL=mongodb+srv://<username>:<password>@cluster0.mongodb.net/devTinder
ALLOWED_ORIGIN=http://localhost:5173
JWT_SECRET=your_jwt_secret
PORT=7777
npm start
Server runs at: http://localhost:7777/
This guide explains how to deploy the full MERN stack (frontend and backend) on a single AWS EC2 instance using Nginx as a web server and reverse proxy.
Prerequisites:
- An AWS account.
- The DevTinder-frontend has been built (
npm run build
). - You have launched an Ubuntu EC2 instance and can connect to it via SSH.
- Node.js, npm, and Nginx are installed on the instance.
- On your local machine, build the React frontend:
# In the frontend project directory npm run build
- Copy the contents of the
dist
folder from your local machine to the Nginx web root on your EC2 instance. You can usescp
for this.# Replace paths and IP address accordingly scp -i /path/to/your-key.pem -r /path/to/frontend/dist/* ubuntu@your-ec2-public-ip:/var/www/html/
-
Clone and Setup Backend on EC2: Connect to your EC2 instance and clone the backend repository.
git clone https://github.com/harshmann10/DevTinder-backend.git cd DevTinder-backend npm install
-
Configure Environment Variables: Create and edit the
.env
file.nano .env
Add your configuration.
PORT
must be7777
to match the Nginx config later.ALLOWED_ORIGIN
should be your server's domain or IP.DATABASE_URL=your_mongodb_connection_string ALLOWED_ORIGIN=http://your-ec2-public-ip JWT_SECRET=a_very_strong_and_secret_key PORT=7777
-
Configure MongoDB Atlas Firewall: In your MongoDB Atlas dashboard, go to Network Access and add the public IP address of your EC2 instance to the IP Access List. This allows your server to connect to the database.
PM2 is a process manager that will keep your Node.js application running in the background.
-
Install PM2 Globally:
sudo npm install pm2 -g
-
Start the Application: Start the server using PM2 and give it a descriptive name.
pm2 start npm --name "devtinder-api" -- start
-
Enable Startup on Reboot: To ensure your app restarts automatically if the server reboots:
pm2 startup
(This will output a command. Copy and run that command to register PM2 as a startup service).
pm2 save
-
Useful PM2 Commands:
pm2 logs devtinder-api
: View real-time logs.pm2 status
: Check the status of your app.pm2 restart devtinder-api
: Restart the app.
Nginx will serve your frontend and act as a reverse proxy for your backend API. This setup allows both to be accessible from the same domain/IP.
-
Edit the Default Nginx Configuration:
sudo nano /etc/nginx/sites-available/default
-
Replace the File Content: Use the following configuration. It serves the React app and forwards any request starting with
/api
to your backend running on port7777
.server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm; server_name your_domain.com or your-ec2-public-ip; # Handle frontend routing location / { try_files $uri $uri/ /index.html; } # Handle backend API proxy location /api/ { proxy_pass http://localhost:7777/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
-
Restart Nginx: Test the configuration and then restart the Nginx service to apply the changes.
sudo nginx -t sudo systemctl restart nginx
β οΈ Important:
In your frontend.env
file, setVITE_BACKEND_URL=/api
This ensures all API requests are correctly proxied through Nginx to your backend.
Your application should now be live at your EC2 instance's public IP address.
The frontend for DevTinder is available at: π DevTinder Frontend Repository
Make sure the backend is running before accessing the frontend.
Explore my additional repositories to deepen your understanding of related topics in the JavaScript ecosystem:
- Namaste Javascript : A repository focused on learning Javascript concepts, from basics to advanced programming.
- Chai aur React : A repository dedicated to mastering React.js, covering foundational and advanced aspects of building interactive UIs.
Since the project is now fully functional, improvements are still welcome!
β
Feel free to open issues for bugs or feature requests.
β
Fork the repository and submit a pull request.
πΉ Real-time notifications using WebSockets
πΉ Messaging System for better user interaction
πΉ Profile Search & Filtering
πΉ Unit Testing for API reliability
This project is open-source and available under the MIT License.