Introduction to Deployment
Deployment is the process of taking an app that runs on your own computer and putting it on servers where real users can reach it through a URL. For a full stack JavaScript app, that usually means building the React frontend into static files, running the Node and Express backend on a hosting service, connecting a production database and setting configuration such as API keys through environment variables. Once authentication and auto logout work locally, deployment is the step that makes the app public.
Development build versus production build
During development, tools like Vite or Create React App run a dev server with hot reload, readable error messages and extra React checks. None of that should reach users. A production build bundles and minifies your code, removes development-only warnings and outputs plain HTML, CSS and JavaScript files in a folder such as dist or build. Those files can be served by any static host.
# Frontend (Vite)
npm run build # creates dist/
npm run preview # check the production build locally
# Backend
NODE_ENV=production node server.js
The pieces that need a home
| Part | What it is after building | Typical hosting |
|---|---|---|
| React frontend | Static files | A static host or CDN, or served by Express |
| Express API | A long-running Node process | A platform service, a container or a virtual server |
| Database | A managed service or a server you run | A hosted MongoDB, PostgreSQL or MySQL instance |
| Secrets and config | Environment variables | The hosting dashboard or a secrets manager |
You can deploy the frontend and backend separately, which scales them independently, or serve the built frontend from Express so everything sits on one domain. Both are valid.
Configuration changes between environments
Things that differ between your laptop and the server should never be hard-coded: the database connection string, the JWT secret, the API base URL the frontend calls, and allowed CORS origins. Read them from environment variables on the server, and from build-time variables such as import.meta.env.VITE_API_URL on the frontend. Remember that anything in a frontend build is visible to every visitor, so keep real secrets on the backend only.
Problems that appear only after deploying
The most common one is refreshing a page like /orders and getting a 404. Client-side routing works because React Router handles the URL in the browser, but on refresh the server looks for a real /orders file. The fix is a fallback rule that serves index.html for unknown paths, configured on the static host or in Express.
Other frequent surprises include API calls still pointing at localhost, CORS errors because the production frontend domain is not allowed by the backend, mixed-content errors when an HTTPS page calls an HTTP API, and the server crashing because it listens on a fixed port instead of process.env.PORT, which many platforms assign.
A basic pre-deployment checklist
- Run the production build locally and click through the main flows.
- Move every secret and URL into environment variables.
- Make the server listen on
process.env.PORT. - Add the SPA fallback so deep links work on refresh.
- Serve everything over HTTPS and set CORS to your real domain.
- Check server logs after the first deploy.
The idea to hold on to
Deploying is mostly about separating what changes per environment from what does not. Build the frontend, run the backend as a managed process, keep configuration in environment variables, and test the production build before users see it.
Ready to master real-world web development?
Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.