REST API for the PrabalBytes portfolio website. Handles contact form submissions, saves messages to MongoDB, and sends email notifications via Resend.
- Runtime — Node.js
- Framework — Express.js
- Database — MongoDB Atlas (Mongoose)
- Email — Resend API
- Hosting — Render (free tier)
backend/
├── models/
│ └── message.js # MongoDB schema for contact messages
├── server.js # Express app, routes, email logic
├── .env # Environment variables (never commit this)
├── .gitignore
└── package.json
Receives form data, saves to MongoDB, and sends emails.
Request Body:
{
"name": "John Doe",
"email": "john@example.com",
"message": "Hey Prabal, I wanted to reach out..."
}Success Response 200:
{
"success": true,
"message": "Message sent successfully"
}Error Response 400:
{
"error": "All fields are required"
}Error Response 500:
{
"error": "Something went wrong"
}Create a .env file in the root folder:
PORT=5000
MONGO_URI=mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/portfolio?retryWrites=true&w=majority
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxx
MY_EMAIL=your@gmail.com| Variable | Description |
|---|---|
PORT |
Port the server runs on |
MONGO_URI |
MongoDB Atlas connection string |
RESEND_API_KEY |
API key from resend.com |
MY_EMAIL |
Your email where you receive notifications |
Resend API Key — Sign up at resend.com → API Keys → Create API Key.
# 1. Clone the repo
git clone https://github.com/Prabalbytes/my_projects.git
cd my_projects
# 2. Install dependencies
npm install
# 3. Create .env file and fill in your values
# (see Environment Variables section above)
# 4. Start the development server
node server.jsServer runs at http://localhost:5000
- Push code to GitHub
- Go to render.com → New Web Service
- Connect your GitHub repo
- Set these in Render dashboard:
Build Command: npm install
Start Command: node server.js
- Add all environment variables in Render's Environment tab
- Deploy — Render gives you a live URL
Note: Render free tier spins down after inactivity — first request may take 50+ seconds.
User submits form
↓
POST /contact (Express)
↓
Validate fields
↓
Save to MongoDB (Message model)
↓
Resend API — sends 2 emails:
├── Notification email → admin (you)
└── Thank you email → client (form submitter)
↓
Return 200 success
Render's free tier blocks outgoing SMTP connections on port 465 (Gmail). Resend uses HTTPS instead, which works perfectly on Render's free tier.
Make sure your .env is never pushed to GitHub:
node_modules/
.env
The frontend (React + Vite) is in a separate repo.
Prabal Das
- Email: prabaldas421@gmail.com
- GitHub: github.com/Prabalbytes
- LinkedIn: linkedin.com/in/prabal-das-a89604296