๐ How to Deploy a Full Stack MERN App Using Netlify, Render, and MongoDB Atlas (Beginner-Friendly Guide)


Want to make your MERN app live for the world to see? Youโre in the right place.
In this guide, youโll learn how to deploy a full stack MERN application with:
React frontend on Netlify
Node.js + Express backend on Render
MongoDB on MongoDB Atlas (cloud)
Weโll go step-by-step so even beginners can follow without confusion.
๐งฑ 1. Project Structure (How Your App Should Look)
Before deploying, make sure your folders are organized like this:
/project-root
โโโ /frontend โ your React app
โโโ /backend โ your Node.js + Express server
And you're using MongoDB Atlas to host your database (more on that later).
๐งฐ 1.5 Get Your App Ready for Deployment
Before you upload to GitHub or deploy, you need to do a few important setup steps:
Step 1: Set Up .env
Files
.env
files store important values like API keys and database links securely.
In your React app (
/frontend/.env
):REACT_APP_API_URL=https://your-backend.onrender.com/api
In your Backend (
/backend/.env
):MONGO_URI=your-mongodb-connection-url JWT_SECRET=your-secret-key PORT=5000
In React, every variable must start with
REACT_APP_
to be available in your app.
โ
Tip: Never share your .env
files publicly!
๐ Add this to your .gitignore
:
.env
Step 2: Check Your package.json
Files
Each folder (frontend
and backend
) has its own package.json
.
In
/frontend/package.json
, make sure these scripts are present:"scripts": { "start": "react-scripts start", "build": "react-scripts build" }
In
/backend/package.json
, check that you have:"scripts": { "start": "node index.js", // or app.js if that's your entry file "dev": "nodemon index.js" }
Render uses the
"start"
script when it runs your backend.
Step 3: Allow Frontend to Talk to Backend (CORS)
In your backend code (index.js
or app.js
), add this:
const cors = require("cors");
app.use(cors({
origin: "https://your-site-name.netlify.app",
credentials: true
}));
This allows your frontend (on Netlify) to access data from your backend (on Render).
Step 4: Clean Up Before Pushing Code
Donโt upload
.env
files to GitHubDelete
node_modules
(Render and Netlify will install them)Run
npm run build
inside/frontend
to check for errors
๐ 2. How to Deploy Frontend on Netlify (React)
๐ช Steps:
Go to https://netlify.com
Click โAdd new siteโ โ Connect GitHub repo
In the settings:
Base directory:
frontend
Build command:
npm run build
Publish directory:
frontend/build
๐ Add _redirects
file (important!)
In /frontend/public
, create a file called _redirects
and add:
/* /index.html 200
/api/* https://your-backend.onrender.com/api/:splat 200
This lets your React routes (like /login
, /dashboard
) work even when refreshed.
๐งฉ Fix Environment Warnings on Netlify
If youโre using something like REACT_APP_CLERK_PUBLISHABLE_KEY
, Netlify may show a warning. To fix it, add a netlify.toml
file:
[build.environment]
SECRETS_SCAN_OMIT_KEYS = "REACT_APP_CLERK_PUBLISHABLE_KEY"
โ๏ธ 3. How to Deploy Backend on Render (Node.js + Express)
๐ช Steps:
Go to https://render.com
Click โNew โ Web Serviceโ
Choose your GitHub repo
Configure settings:
Root Directory:
backend
Build Command:
npm install
Start Command:
npm start
In Environment Variables, add:
MONGO_URI
JWT_SECRET
Any others your backend needs
๐ Common Issues:
Error | Fix |
500 server error | Check MONGO_URI , and logs in Render |
MongoDB timeout | Use correct connection string from MongoDB Atlas |
Build failed | Make sure backend is selected as root directory |
๐ 4. Set Up MongoDB Atlas (Free Cloud Database)
๐ช Steps:
Create a free cluster
Add a new database user (username/password)
Go to Network Access and allow:
0.0.0.0/0 (allows all IPs โ good for development)
Copy the Connection String and paste it in your backend
.env
asMONGO_URI
๐ 5. Connecting Frontend to Backend
In your React app, call backend routes like:
fetch("https://your-backend.onrender.com/api/posts")
Or if you're using the _redirects
file:
fetch("/api/posts")
Both work โ just make sure your API URLs are correct!
๐งช 6. Test Everything!
After deploying:
โ
Open your Netlify frontend URL
โ
Click around your app
โ
Check browser DevTools โ Network tab for errors
โ
Test APIs directly using Postman or browser
โ
View logs on Netlify + Render for debugging
๐ 7. Common Errors and Quick Fixes
Problem | What to Check |
โ 500 Error | Wrong DB URI or missing env vars |
๐ 404 on routes | Missing _redirects file |
๐ CORS error | Backend must allow Netlify domain |
๐ MongoDB timeout | Use correct URI & allow access in Atlas |
โ ๏ธ Build fails | Fix scripts, directory paths |
๐ฏ 8. Final Tips for a Smooth Deployment
โ Always redeploy after changing
.env
or configโ Use logs to fix issues quickly
๐ Never put real secrets in frontend
.env
๐ After launch, restrict MongoDB IP access to your server only
Congrats! ๐ You now have a fully deployed MERN app:
๐ป React frontend on Netlify
๐ง Express backend on Render
๐ข MongoDB database on Atlas
Happy coding, and see you online! ๐
Subscribe to my newsletter
Read articles from Md Asif Siddiqui directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
