Skip to content

Expert · Deploying and running the app · topic 24 of 34 · 30 min

Where to deploy

Explanation

Deploying means putting your app on computers that are always on and reachable from the internet. The Notes app has three parts: the React frontend, the Express API and the PostgreSQL database, and each needs a home. You choose between easy platforms, a server you control yourself, and managed databases, then connect your own domain with HTTPS.

What deploying means

Deploying is copying your app to a server (a computer in a data centre that never sleeps), starting it, and giving it an address people can type. The Notes app has three parts, and each needs a home: the frontend (built files: HTML, CSS and JavaScript), the API (a Node.js process that must keep running) and the database (PostgreSQL, which must keep data safe for years).

Think of it like this: Think of opening a shop. You can rent a ready shop in a mall: the mall gives you electricity, security guards and cleaning, but you follow its rules and the rent grows with your space. Or you can rent an empty room on the main road: it is cheaper and you decide everything, but you fix the shutter, the wiring and the lock yourself. App platforms are the mall. A VPS is the empty room.

Four kinds of homes

KindWhat it does for youExamplesGood for
Static / frontend hostBuilds your React app from GitHub and serves the files from a CDN (copies in many cities)Vercel, Netlify, Cloudflare PagesThe React frontend
App platform (PaaS)Runs your Node server from a Git repo; handles HTTPS, restarts and logsRender, Railway, Fly.ioThe Express API
VPS (virtual private server)Gives you a whole Linux machine with full (root) access; you set up everythingDigitalOcean Droplets, AWS Lightsail, Hetzner CloudFull control and a fixed monthly bill
Managed PostgreSQLRuns the database for you, with backups and updatesNeon, Supabase, Render Postgres, AWS RDSThe database

PaaS means Platform as a Service: you give it code, it gives you a running app. If you built the Notes app with Next.js instead (pages and API routes in one project), one project on Vercel can serve both. You still need a managed PostgreSQL database next to it.

Trade-offs: ease, control and cost

  • Platforms are the easiest: push to GitHub and the new version goes live. You get less control, and the bill grows with traffic and extra services.
  • Free plans are great for learning and demos. Many free services sleep when nobody uses them, so the first request after a quiet time is slow (a cold start). Do not run a paying client on them.
  • A VPS gives full control and a predictable price, but you must install security updates, set a firewall, watch the disk and set up backups yourself.
  • A managed database is usually worth paying for. Backups and safe upgrades are hard to get right, and a lost database cannot be rebuilt.
Careful: Free tiers and prices change often, sometimes every few months. A number in last year's blog post may be wrong today. Always check each provider's official pricing page before you choose, and before you quote a monthly cost to a client.

The VPS way: Nginx in front of Node

On a VPS you usually put Nginx in front of your app. Nginx is a reverse proxy: a server that receives every request from the internet and passes it on to your app, which listens on a private port such as 3000. Nginx also serves the built React files and handles HTTPS. A process manager keeps the API alive: systemd (built into Linux) or PM2 (a Node tool) restarts it after a crash or a reboot. Another common way is to run each part in a Docker container.

output
server {
    server_name notesapp.in;
    root /var/www/notes/dist;          # built React files

    location / {
        try_files $uri /index.html;    # let React Router handle paths
    }

    location /api/ {
        proxy_pass http://127.0.0.1:3000;   # the Express API
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
A small Nginx site for the Notes app on a VPS. Certbot later adds the HTTPS lines to this file.

Region, domain and HTTPS

A region is the city where the data centre stands. If most users are in India, pick Mumbai, or the nearest region your provider has (often Singapore). Keep the API and the database in the same region. One page load can make several database queries, and if the API is in the USA and the database in Mumbai, every query crosses the world and back.

DNS (the Domain Name System) turns a name like notesapp.in into an address computers can reach. You add records at the company where you bought the domain. An A record points a name to an IPv4 address (like 203.0.113.10), an AAAA record to an IPv6 address, and a CNAME record points a name to another name (like notes-api.onrender.com). The bare domain, called the apex (notesapp.in with nothing in front), cannot be a CNAME; many DNS providers offer an ALIAS record (or "CNAME flattening") for it, or you use an A record.

NameTypeValueWhy
@ (notesapp.in)A203.0.113.10The apex points to the VPS or host IP the host tells you
wwwCNAMEnotesapp.inwww.notesapp.in goes to the same site
apiCNAMEnotes-api.onrender.comapi.notesapp.in goes to the API on the platform

HTTPS needs a certificate, a small file that proves the site really is notesapp.in. Let's Encrypt is a free certificate authority. Platforms get and renew its certificates for you once your DNS points to them. On a VPS, the Certbot tool gets the certificate and renews it automatically before it expires.

Tip: Put the API on a subdomain of the same site (api.notesapp.in next to notesapp.in), or serve it under notesapp.in/api. The browser then treats both as the same site, so the SameSite=Lax session cookie from the auth module keeps working and CORS stays simple.

Watch the lesson

Where to deploy · 1/7

Deploy = always on + reachable

Our Notes app works on our laptop. Now we put it on the internet. This is called deploying.

Prefer a video by a teacher? Find free videos on “deploy react express postgresql app render vercel tutorial” on YouTube ↗

In real life: A college results site on results day

A college puts its exam results online. On most days a few hundred students visit; on results day thousands arrive in the same ten minutes. The team serves the React frontend from a static host with a CDN, so the pages load fast in every city. The small API runs on an app platform in the region nearest to India, with the managed PostgreSQL database in the same region. Before results day they move off the free plan (which sleeps when idle) to a paid instance, check the provider's pricing page for the real cost, and point results.college.example to it with a CNAME. HTTPS comes free with the platform.

Practice (0/3 done)

Task 1 · Code · Javascript

Write pickDnsRecord(name, target) that returns the DNS record type to use. Rules in order: if target is an IPv4 address (four numbers joined by dots, like "203.0.113.10") return "A"; if target contains ":" (an IPv6 address) return "AAAA"; if target is a host name and name is "@" (the apex) return "ALIAS"; otherwise return "CNAME".

Task 2 · Code · Javascript

A deploy plan looks like { frontend: { host }, api: { host, region }, database: { host, region }, https }. Write checkDeployPlan(plan) that returns an array of problems, in this order: "frontend host missing", "api host missing", "database host missing", "api and database regions differ" (only when both regions are given and are not equal), "https is off" (when https is not true). A good plan returns [].

Task 3 · Practice

Write a one-page deploy plan for the Notes app for a small college with about 500 students. Say where each part runs, why, and how the domain and HTTPS work. Use each provider's official pricing page for costs and write down the date you checked.

Quick quiz

Question 1

1.Which is a reverse proxy commonly put in front of a Node.js app on a VPS?

Question 2

2.Your users are in India and your database is in Mumbai. Where should the API run?

Question 3

3.You want api.notesapp.in to point to notes-api.onrender.com. Which DNS record do you add?

Question 4

4.A demo API on a free plan answers slowly only for the first request after a quiet hour. What is the likely reason?

Question 5

5.What is the best way to know the current free tier and price of a host?

Read more (free)

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

← Previous: Adding image attachments to notes