Skip to content
EzzyWeb

Level 5, Professional Practice, Chapter 23 of 24

Deployment — Shipping Your Work

Why this matters

Every project you've built so far has existed only on your own computer, viewable only by you in your own browser. That's a huge gap between what you've learned to build and what makes it real: a website only truly counts as finished once someone else can visit it. Deployment is the process of publishing your code to a server so it's accessible on the public internet, and it's often treated as intimidating when in practice, modern tools have made it remarkably approachable.

This chapter closes the loop between everything you've learned about writing code and the experience of sharing it. You'll learn what actually happens between clicking 'deploy' and a URL working in someone else's browser, how to configure a project for a production build, and how to keep a live site updated as you continue improving it.

The lesson

What deployment actually means

When you run a project locally with a tool like Vite's dev server, your computer is temporarily acting as a web server, but only your machine can reach it. Deployment moves that responsibility to a server that's always on and connected to the public internet, then points a domain name at it so people can type a URL and reach your files. Static sites, meaning sites made of HTML, CSS, and JavaScript with no server-side code required, are the simplest and cheapest to deploy, and modern hosts like Netlify, Vercel, and GitHub Pages have made this close to a one-click process for exactly this kind of project, which covers everything you've built in this course.

Before deploying, you typically run your project's build command, the same npm run build step from the developer workflow chapter, which compiles your source files into an optimized dist folder containing minified HTML, CSS, and JavaScript ready for production. Deployment platforms are usually configured to run this build step automatically whenever you push new code, then serve the resulting files. Understanding this pipeline demystifies what's happening: your source code isn't uploaded directly, a processed and optimized version of it is, which is part of why performance techniques from earlier in this level matter even before a single visitor arrives.

A typical deployment workflow

  • Push your project to a Git repository hosted on GitHub (or a similar service).
  • Connect that repository to a hosting platform like Netlify or Vercel.
  • Configure the build command (often npm run build) and the output directory (often dist).
  • The platform builds your project and publishes it to a live URL automatically.
  • Every future push to your main branch triggers a new automatic deployment, known as continuous deployment.
A minimal Netlify configuration file
Terminal
1# netlify.toml2[build]3  command = "npm run build"4  publish = "dist"56[[redirects]]7  from = "/*"8  to = "/index.html"9  status = 200
Placing a netlify.toml file at your project root tells the platform exactly how to build and publish your site.

That redirect rule solves a specific and common problem for single-page applications: if your JavaScript handles routing on the client side (showing different views without a full page reload) and a visitor refreshes the page on a route like /about, the server needs to know to still serve index.html and let your JavaScript take over from there, rather than returning a 404 because no literal /about file exists on the server. This is a good example of how deployment decisions connect directly back to how your JavaScript is structured.

Environment variables and keeping secrets safe

If your project uses an API key, as you likely did in earlier chapters working with external APIs, you must never commit that key directly into your source code, especially once it's pushed to a public GitHub repository, since anyone can then read and misuse it. Instead, secrets belong in environment variables: values kept outside your codebase and injected at build or run time. Locally, these often live in a .env file that's listed in .gitignore so Git never tracks it; on a hosting platform, you configure the same variables through that platform's dashboard, where they stay private but are still available to your build process.

Using an environment variable in a Vite project
JavaScript
1// .env (never committed to Git)2// VITE_WEATHER_API_KEY=abc12334const apiKey = import.meta.env.VITE_WEATHER_API_KEY;56fetch(`https://api.example.com/weather?key=${apiKey}&city=Nairobi`)7  .then((res) => res.json())8  .then((data) => console.log(data));
Vite only exposes environment variables to your JavaScript if their names are prefixed with VITE_.

It's worth being clear-eyed about a limitation here: anything shipped to the browser, including a key exposed through import.meta.env, is ultimately visible to anyone who inspects the network requests or bundled JavaScript. Environment variables at build time protect your keys from appearing in your Git history and source code, which matters, but they don't make a key invisible to a determined visitor. For anything sensitive, like a key with billing attached, the safer long-term pattern is routing requests through a small server-side function you control, which is a natural next step beyond what this course covers.

Try it yourself

This sandbox simulates a deployment pipeline as plain JavaScript so you can see the stages involved without needing an actual host. Read through the steps, then modify the buildSteps array to add a 'run tests' step before 'optimize assets', and re-run the pipeline.

Live preview

Chapter boss project

Boss Project: Ship a Real, Live Website

Take a project you built earlier in this course, or combine a few small ones into one small site, and deploy it to a real, public URL using a free host such as Netlify, Vercel, or GitHub Pages. Configure the build command and output directory correctly and confirm the live site actually works, including any JavaScript features, not just the visible layout.

If your project uses an API key anywhere, move it into an environment variable rather than leaving it hardcoded, and configure the same variable through your hosting platform's dashboard so the deployed version still works correctly.

Make one visible improvement to your project, commit it, push it, and confirm the live site updates automatically without you doing anything beyond the push. Share the resulting URL somewhere you can find it again, like a personal notes file or your GitHub README.

  • If a deploy fails, always read the build log first; it usually states exactly which command failed and why.
  • Double-check your publish directory matches your build tool's actual output folder (commonly `dist` for Vite).
  • If routes or refreshes return a 404 on a single-page project, you likely need a redirect rule like the one shown in this chapter's lesson.
  • Test your live site in an incognito window or on your phone, since a page can behave differently once it's no longer running on your local machine.

Level-up checklist

Tick these off once each one is true for you.