๐Ÿš€ 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 GitHub

  • Delete 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:

  1. Go to https://netlify.com

  2. Click โ€œAdd new siteโ€ โ†’ Connect GitHub repo

  3. 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:

  1. Go to https://render.com

  2. Click โ€œNew โ†’ Web Serviceโ€

  3. Choose your GitHub repo

  4. Configure settings:

    • Root Directory: backend

    • Build Command: npm install

    • Start Command: npm start

  5. In Environment Variables, add:

    • MONGO_URI

    • JWT_SECRET

    • Any others your backend needs

๐Ÿ›  Common Issues:

ErrorFix
500 server errorCheck MONGO_URI, and logs in Render
MongoDB timeoutUse correct connection string from MongoDB Atlas
Build failedMake sure backend is selected as root directory

๐Ÿƒ 4. Set Up MongoDB Atlas (Free Cloud Database)

๐Ÿชœ Steps:

  1. Go to https://www.mongodb.com/cloud/atlas

  2. Create a free cluster

  3. Add a new database user (username/password)

  4. Go to Network Access and allow:

     0.0.0.0/0   (allows all IPs โ€” good for development)
    
  5. Copy the Connection String and paste it in your backend .env as MONGO_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

ProblemWhat to Check
โŒ 500 ErrorWrong DB URI or missing env vars
๐Ÿ”„ 404 on routesMissing _redirects file
๐Ÿ›‘ CORS errorBackend must allow Netlify domain
๐Ÿ•’ MongoDB timeoutUse correct URI & allow access in Atlas
โš ๏ธ Build failsFix 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! ๐Ÿ’™

0
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

Md Asif Siddiqui
Md Asif Siddiqui