Full Stack JS

Chapter 20
0%

Chapter 20: Deploy to Production

Take your full-stack application from your computer to the internet for the world to use.

Deployment Options
Deploy Frontend
Deploy Backend
Connect Everything
CI/CD
Quiz

Deployment Options

Deploying your app is like opening a restaurant. You have been cooking amazing dishes in your kitchen (localhost). Now it is time to find a location (hosting provider), set up the dining area (frontend), the kitchen (backend), the pantry (database), and open the doors to the public. Each part needs its own setup, but once it all comes together, you are serving customers!

Different parts of your full-stack app can be deployed to different services:

ComponentPopular OptionsFree Tier?
Frontend (React)Vercel, Netlify, GitHub PagesYes
Backend (Node/Express)Railway, Render, Fly.ioYes (limited)
DatabaseSupabase, PlanetScale, RailwayYes (limited)
Full StackRailway, Render, DigitalOceanVaries
For beginners, Vercel (frontend) + Railway (backend + database) is a great combination. Both have generous free tiers and are very beginner-friendly.

Deploy Frontend

Deploying a React frontend to Vercel takes less than 5 minutes:

Terminal — Deploy to Vercel

Environment Variables on Vercel

Vercel Dashboard — Environment Variables

Deploy Backend

Deploying a Node.js backend to Railway:

Steps — Deploy Backend to Railway

Update Database Config for Production

JavaScript — Database Config for Dev & Production

Connect Everything

Now your frontend and backend are deployed separately. You need to connect them:

Production Architecture

User's Browser

Frontend (Vercel) — https://myapp.vercel.app
↓ API calls
Backend (Railway) — https://myapi.up.railway.app

Database (Railway PostgreSQL)
JavaScript — Frontend API Configuration
JavaScript — Backend CORS for Production
CORS is critical! Without proper CORS configuration, your frontend cannot make API calls to your backend. The browser blocks cross-origin requests by default for security.

CI/CD (Continuous Integration / Continuous Deployment)

CI/CD is like an automatic assembly line in a factory. Instead of manually inspecting and shipping each product (deployment), the assembly line automatically tests every product (CI) and ships it if it passes all checks (CD). Every time you push code, tests run automatically, and if everything passes, it gets deployed.

CI (Continuous Integration) = Automatically run tests when code is pushed
CD (Continuous Deployment) = Automatically deploy when tests pass

.github/workflows/ci.yml — GitHub Actions

Deployment Checklist

#TaskStatus
1Environment variables set on hosting platformRequired
2Database migrated / syncedRequired
3CORS configured for production domainRequired
4HTTPS enabled (most hosts do this automatically)Required
5Security middleware (helmet, rate limiter) activeRecommended
6Error logging set upRecommended
7CI/CD pipeline configuredRecommended
8Custom domain connectedOptional

📝 Chapter 20 Quiz

1. Which platform is best for deploying a React frontend?

Railway
Vercel
SQLite Cloud
Docker Hub

2. Why would your deployed frontend fail to fetch data from your deployed backend?

Because they are on different hosting providers
Because the frontend needs a database too
CORS is not configured to allow the frontend domain
Because fetch() only works on localhost

3. How should you set environment variables in production?

Through the hosting platform's dashboard or settings
Commit the .env file to GitHub
Hard-code them in the source code
Email them to the server admin

4. What does CI/CD automate?

Writing code and fixing bugs
Creating Git branches
Database backups only
Testing code and deploying when tests pass

5. In a Vite/React app, what prefix must frontend environment variables have?

REACT_APP_
VITE_
PUBLIC_
No prefix needed

Congratulations! You Did It!

You have completed the Full Stack JavaScript course!

You now have the knowledge to build and deploy full-stack web applications. Here is what you have learned:

The best way to learn is to build projects. Start with a personal project, contribute to open source, and never stop learning. You have got this!

← Chapter 19: Environment & Build 🏠 Course Home