Shipping a MERN app to production

By Shashank Sharma Checklist 3 min read Published August 2026

Shipping a MERN app to real users is a different bar than running it on localhost. Work through this before your first deploy — it covers the things that break in production but never show up in development.

Environment & config

  • Load config from the environment — never hardcode URLs, ports, or keys.
  • Validate required env vars at startup and fail fast if any are missing.
  • Keep secrets out of git — use a secrets manager or platform env vars, and rotate anything that leaked.
  • Set NODE_ENV=production so Express and dependencies use their optimized paths.
// fail fast if config is missing — better a clear crash than silent bugs
const required = ["MONGO_URI", "JWT_SECRET", "PORT"]
for (const key of required) {
  if (!process.env[key]) throw new Error(`Missing env var: ${key}`)
}

Security

  • Enforce HTTPS and set security headers (e.g. with a headers middleware).
  • Authenticate and authorize every non-public route.
  • Validate and sanitize all input at the boundary.
  • Rate-limit auth and public endpoints.
  • Lock down CORS to known origins.
Practice this
Build a connected MERN app
16 challenges, from Mongoose models and Express endpoints to data-driven React screens.
Start practicing

Database

  • Use a managed MongoDB with backups and monitoring enabled.
  • Index the fields you query and sort — verify with explain().
  • Reuse a single connection pool; don't reconnect per request.
  • Restrict database network access to your app, not the public internet.

Performance

  • Run Node behind a process manager with clustering and graceful shutdown.
  • Enable gzip/brotli compression for responses.
  • Cache hot reads where it makes sense; add a CDN for static assets.
  • Build the React client for production and serve it minified.

Error handling & logging

  • Add a central error-handling middleware that returns safe responses.
  • Never expose stack traces or internals to clients.
  • Log structured errors and handle unhandledRejection / uncaughtException.
  • Report errors to a tracking service.

Observability

  • Add a health-check endpoint for your platform's probes.
  • Collect metrics and request logs so you can diagnose issues.
  • Set up alerts on error rate and latency.

Pre-deploy checklist

  • Config from env, required vars validated, secrets out of git
  • HTTPS, headers, auth, validation, rate limiting, CORS in place
  • Managed DB with backups, indexes, and restricted access
  • Process manager, compression, caching, production client build
  • Central error handler, structured logs, error reporting
  • Health check, metrics, and alerts wired up

FAQ

What's the most overlooked step before a MERN deploy?

Configuration and secrets. Hardcoded values, missing environment variables, and committed credentials cause more first-deploy failures than code bugs. Load everything from the environment and validate it at startup.

Do I need a process manager for Node in production?

Yes. Run Node behind a process manager or container orchestrator that restarts on crash, runs multiple instances across CPU cores, and handles graceful shutdown. A bare `node server.js` is not production-ready.

How should I handle errors in production?

Never leak stack traces to clients. Use a central error handler that returns a safe, consistent response, logs the full error server-side, and reports it to an error-tracking service so you find out before users do.

Put it into practice

Solve real challenges in a full browser IDE — graded automatically.

Open the learning path

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.