Deploy to production
In the previous chapter, weāve seen how to run a development server locally on your laptop. But since your laptop is not always running and connected to the internet, you need a server in some data center to host your production website. If you donāt want to deploy your website to production (where other people on the internet can see it), you can also skip this chapter for now.
Deploy static site with CI/CD
If you have a static site, you can deploy to GitHub Pages, Netlify, or any other CDN. You could even serve the files from a static file server like nginx.
Letās look at how you can generate your static site within a Continuous Integration / Continuous Delivery (CI/CD) service. This ensures a reproducible environment (i.e. that it not only works on your computer), and makes sure that you havenāt forgotten to add any needed files to git (which can happen easily). Basically, this is just running the following command on the CI/CD server instead of on your laptop.
-
Deno deno task generateCopied! -
Node.js pnpm run generateCopied! -
Bun bun run generateCopied!
Depending on whether you use Deno or Node.js, and what your deploy target is, we may have exactly the right documentation for you. Otherwise you can probably adapt them to your use-case.
| Deploy to GitHub Pages |
Deploy to Cloudflare |
Deploy to Netlify |
|
|---|---|---|---|
| SSG with Deno | docs | docs | docs |
| SSG with Node.js | docs | docs | docs |
Deploy server to production
Since static sites are completely pre-generated, theyāre usually faster and cheaper to host than running a server. However, as weāll see in the next couple of chapters, there are some things that you cannot do with a static site.
Since GitHub Pages only offers static site hosting, if you need to dynamically generate pages on-demand, you need a production server, as offered by Deno Deploy, Fly.io, Render, or any server that can run Deno, Node.js or Bun ā even if itās via Docker.
Basically itās just running the following command on their server:
deno run --allow-read --allow-net --allow-env server.ts
node server.ts
bun server.ts
Be sure to run one of those in production and not deno/pnpm/bun run start, as those run with the --watch flag that restarts the server on file changes ā great for local development, but unnecessary in production.
Cloudflare Workers
Cloudflare Workers come with their own JavaScript runtime called workerd. They donāt support running on-demand code with Deno, Node.js or Bun. To run your server code on-demand on the edge using Cloudflare, use the Mastro template for Cloudflare Workers. Either via the template repo or:
pnpm create @mastrojs/[email protected] --cloudflare
We donāt have specific docs for every combination of JavaScript runtime and hosting provider, but here are some starting points:
| Deploy to Deno Deploy | Deploy to Render | |
|---|---|---|
| Server with Deno | docs | docs |
| Server with Node.js | - | docs |
| Server with Bun | - | docs |
In the next chapter, letās look at some fun things you can do with a server.