Module 75 : Deploying JavaScript Apps with Netlify or Vercel.
continuous deployment (CD) works with Netlify and Vercel and why it matters.
Netlify Docs
+1
Deploy a static or single-page JavaScript app via drag-and-drop, via Git integration, and via the CLI.
Netlify Docs
+1
Configure build commands, publish directories, environment variables, and redirects.
Netlify Docs
+1
Add and test serverless functions (Netlify Functions, Vercel Serverless/API routes) and call them from the frontend.
Netlify Docs
+1
Use preview deploys / branch deploys and set up staging workflows.
Netlify Docs
Understand performance trade-offs: SSG vs SSR vs Edge functions, caching and CDN considerations. Prerequisites: Git basics, Node.js/npm, a sample JavaScript app (vanilla, CRA, Vite, Next.js etc.), basic terminal competence, GitHub/GitLab/Bitbucket account.
3. Continuous Deployment (CD)
CD = connect your Git repo to the hosting platform so every push or PR creates a deploy — automated build → artifact → global CDN. This creates reproducible deployments and shortens feedback loops. Netlify and Vercel both provide Git integrations that automatically run your build command and publish results on successful commits.
Netlify Docs
+1
Build steps
runs tools (npm run build, vite build, next build) and emits static files (dist/ or out/) or server bundles. Configure the platform with the build command + publish directory.
Netlify Docs
serverless functions or SSR code run on demand (not part of static asset hosting). Netlify exposes “Functions” (serverless) and Vercel has Serverless/Edge functions or API routes. Use functions for secure secrets, third-party API calls, or dynamic server logic.
Netlify Docs
+1
Preview Deploys & Branch Deploys
Platforms generate preview URLs for branches and PRs — crucial for reviewing changes before merging. Netlify supports deploy previews per PR and branch deploy configs; Vercel creates preview deployments for each PR and commit. how to use previews for QA.
Netlify Docs
+1
Serverless functions: constraints & patterns
Serverless functions are ephemeral and stateless: cold starts, limited execution time and memory. Use them for API endpoints, webhooks, form processing, auth flows, and offloading secret logic from client code. Netlify functions live in netlify/functions and are packaged at build time. Vercel exposes api/* routes and edge functions.
Netlify Docs
+1
4. worked
assume you already have a small project with package.json and a build script (e.g. npm run build produces dist/ or build/). Use GitHub for the examples.
Quick static deploy to Netlify (GUI)
Build locally to verify:
npm install npm run build # verify that build output exists, e.g. ./dist or ./build
Go to Netlify → New site → “Drag & drop” and drop the build folder (or zipped project). The site will be published with a preview URL.
Netlify Docs
Drag & drop is perfect for absolute no Git needed. After drag & drop, show them how to view site settings (domain, SSL, deploy logs).
the build output directory and why it must contain an index.html.
Deploy from Git to Netlify
Push app to GitHub.
In Netlify dashboard: Add new site → Import from Git → choose provider → authorize → select repo.
Fill in build command (e.g. npm run build) and publish directory (dist or build). Click Deploy. Netlify runs the build and publishes.
Netlify Docs
Add an environment variable
In Netlify: Site settings → Build & deploy → Environment → add API_KEY (masked). Use process.env.API_KEY in serverless function or import.meta.env depending on framework ( framework nuance).
Netlify serverless function (simple example)
Project structure:
/netlify/functions/hello.js
netlify/functions/hello.js
exports.handler = async (event, context) => { return { statusCode: 200, body: JSON.stringify({ msg: "Hello from Netlify Functions" }) }; };
Locally test with Netlify Dev:
npm i -g netlify-cli netlify dev # or `netlify dev --live` to share
From frontend: fetch('/.netlify/functions/hello') and show JSON.
Notes: Netlify CLI can build + deploy and exposes function logs.
Netlify Docs
+1
Deploy a React (Vite/CRA) app with Vercel (GUI)
Push project to GitHub.
On Vercel: New Project → Import Git Repository, choose framework preset if prompted (Vercel can auto-detect).
Vercel auto-fills Build Command and Output Directory; confirm and deploy. Vercel will create a production URL and preview URLs for PRs.
Vercel
+1
Demonstrate a small change in a branch → push → show preview URL for that branch.
Vercel CLI & API route (example)
Install and login:
npm i -g vercel vercel login # from project root vercel
Create an API route api/hello.js:
// api/hello.js export default function handler(req, res){ res.status(200).json({ msg: "Hello from Vercel API route" }); }
Test locally:
vercel dev # visit http://localhost:3000/api/hello
Deploy:
vercel --prod
Caveat: Vercel’s model differs by framework (Next.js gets tighter integration).
Vercel
+1
Config files (examples)
netlify.toml (optional control)
[build] command = "npm run build" publish = "dist" [dev] command = "npm run dev" [[redirects]] from = "/*" to = "/index.html" status = 200
Netlify recognizes _redirects and netlify.toml for custom routing and headers.
Netlify CLI command reference
vercel.json (optional)
{ "builds": [ { "src": "package.json", "use": "@vercel/static-build", "config": { "distDir": "dist" } } ], "routes": [ { "src": "/api/(.*)", "dest": "/api/$1.js" } ] }
Vercel auto-detects many frameworks; vercel.json is only necessary for fine-grained control.
Vercel
5. Exercises
Exercise set (individual)
Deploy a plain HTML/CSS/JS site to Netlify using drag & drop. (Deliverable: public URL)
Deploy the same site to Vercel via Git import. (Deliverable: production URL + preview URL for a branch)
Add a serverless function that returns server time; call it from the frontend and display the time (both platforms). (Deliverable: code + screenshot)
Add one environment variable (e.g., FEATURE_TOGGLE) and demonstrate it using a serverless function. (Deliverable: screenshot of env var in dashboard & functioning app)
Implement a redirect rule (e.g., redirect /old to /new) and show proof. (Deliverable: redirect behavior demo GIF).
Grading rubric (total 100)
Deployments successful & accessible (30)
Serverless function implemented & secure (20)
Environment variable used & not leaked in client code (15)
Correct build & config files present (netlify.toml/vercel.json as needed) (15)
Proper documentation in README with deployment steps (10)
CI test that runs before deploy and publishes artifact (10)
6. Troubleshooting checklist
Build fails on platform but works locally: check Node version & install settings; set Node version via engines in package.json or via platform settings.
Wrong publish folder: confirm dist vs build.
Netlify Docs
Serverless function 502/timeout: check logs in platform dashboard; watch for cold start / long running synchronous operations.
Netlify Docs
Secrets showing up in client: ensure secret used only in serverless function or read at build-time (and not exposed to client bundle).
DNS/custom domain HTTPS issues: ensure domain is pointed to platform nameservers or add CNAME/A records per platform docs; let the platform provision SSL (usually automatic).
7. Advanced topics & research directions
These are suggested mini-projects, or research assignments.
SSR vs SSG vs Edge — empirical performance measurements (TTFB, Time to Interactive) when using SSR (Next.js on Vercel) vs SSG on Netlify/Vercel vs Edge Functions. Measure cold starts, latency across regions, and cost behavior.
Vercel
+1
Function cold starts & warmers — experiment with function runtimes (Node vs Deno/Edge), memory allocation, and warm-up strategies. Collect timing and cost metrics.
Deploy artifacts & CI gating — evaluate patterns to run tests (GitHub Actions) before allowing platform to deploy; artifacts vs building on platform. Explore recommended workflows that integrate CI and Netlify/Vercel. (Community discussions and platform docs show different approaches.)
Netlify Support Forums
+1
Advanced caching, CDN headers, and cache invalidation — study cache-control strategies, immutable asset hashing, and cache purging APIs.
Comparative case study — pick a nontrivial app (Next.js + API integrations) and deploy to both platforms; compare developer DX, performance, ergonomics, team collaboration features (preview URLs, role permissions), and cost at scale.
8. (short snippets)
Explain — Why deploy to Netlify/Vercel?“Netlify and Vercel let us focus on writing apps, not managing servers. You push code and the platform runs the build, uploads assets to a global CDN, and any server code is exposed as serverless endpoints. This reduces ops overhead and speeds up developer feedback via preview URLs for branches and PRs.”
Netlify Docs
+1
explain serverless to beginners
“Serverless functions are tiny backend endpoints you drop into your project. They are invoked on demand, scale automatically, and are ideal for things that need secrets (API keys) because the secret stays on the server — not the browser.”
9. Netlify — Getting started & Start pathways.
Netlify Docs
Netlify — Create deploys & Build configuration overview.
Netlify Docs
+1
Netlify CLI & Functions docs (CLI deploy, Netlify Dev, Functions API).
Netlify CLI command reference
+2
Netlify Docs
+2
Vercel — Getting started, deployments overview, and CLI docs.
Vercel
+2
Vercel
+2
Vercel : Deploying React with Vercel.
Vercel