Stop 13 · Testing & DeploymentProjects · 1/1

Deploy a MERN App End to End

Part of the MERN Stack Roadmap

In short

A live link on your resume beats a GitHub repo nobody runs. This project takes one of your apps all the way: production database, deployed API, deployed frontend, tests in CI and every environment variable in its right place.

Take one of your MERN apps from your laptop to a live URL with production MongoDB, a deployed API, a deployed frontend, tests in CI and environment variables set correctly.

The jaadu waves a green flag on a railway platform as a shiny new train pulls out of the station on its very first trip.

Think of it like this

Launching a new train route

Before a new Vande Bharat route opens, the track is laid (database), stations are built (API), the coaches are painted and fitted (frontend), signals are tested on every run (CI), and the timetable is published (live URL). Skip one and the first passenger finds out.

Watch it happen

Release path

Atlas
API host
Frontend
CI
Live

1/5Production cluster, app user and network rules. Copy the connection string.

The big ideas

What you need to know

Two URLs talk to each other

The frontend knows the API URL through VITE_API_URL. The API allows the frontend through CORS with CLIENT_URL.

Cookies across sites

If the frontend and API are on different sites, auth cookies need sameSite: "none", secure: true and CORS credentials, or put both under one domain with a rewrite.

SPA rewrites

React Router paths like /orders/42 must serve index.html on refresh. Add a rewrite rule on the frontend host.

Smoke test like a user

Signup, login, create, refresh a deep link, logout, on desktop and phone. Fix anything before you share the link.

See it in code

Walk through the code

json
1{2  "rewrites": [3    { "source": "/api/(.*)", "destination": "https://notes-api.onrender.com/api/$1" },4    { "source": "/(.*)", "destination": "/index.html" }5  ]6}

1/2Requests to /api on the frontend domain are forwarded to the API, so the browser sees one site and cookies stay first-party.

client/vercel.json: proxy /api to the deployed Express API and send every other path to the React app.

Save yourself the pain

Common mistakes

Oops

Building the frontend with VITE_API_URL=http://localhost:5000.

Do this instead

Vite bakes env vars in at build time. Set the production value on the host and rebuild.

Oops

Deep links returning 404 after refresh.

Do this instead

Add the catch-all rewrite to index.html on Vercel, Netlify or Nginx.

Oops

Sharing the link without testing signup on a fresh browser.

Do this instead

Use an incognito window and your phone. That's where cookie and CORS issues appear.

Your mission

Go live

~240 min

Quick check

Refreshing https://myapp.vercel.app/notes/42 gives a 404, but the home page works. What is missing?

Go deeper

  1. 1Use a custom domain or subdomain if you have one.
  2. 2Check CORS, cookies and HTTPS work across the two deployed URLs.
  3. 3Write a deployment section in your README.

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge