Deploy a Hydrogen app
You can deploy a Hydrogen app to most Node.js and Worker runtimes. This guide describes how to deploy a Hydrogen app to Oxygen, Node.js, Docker, Cloudflare Workers, and Netlify.
Requirements
Anchor link to section titled "Requirements"You're using the most recent version of Hydrogen. The latest release gives you the benefits of performance enhancements, new components, and other best practices.
Deploy to Oxygen
Anchor link to section titled "Deploy to Oxygen"Oxygen is Shopify's recommended deployment platform for Hydrogen apps.
Deploy to Node.js
Anchor link to section titled "Deploy to Node.js"You can deploy your Hydrogen app to Node.js, an open-source JavaScript runtime environment.
Check the port (
$PORT
) that's specified in theserver.js
file.Run your Hydrogen app on the port specified by executing the following commands:
If you're using the default port, then the production version of your app will be running at http://localhost:8080.
Apply extra middleware
Anchor link to section titled "Apply extra middleware"If you're using the default server entry point in the build:server
script (@shopify/hydrogen/platforms/node
), then the generated server bundle (dist/server/index.js
) consists of a simple Node.js server that uses Connect middleware.
This bundle also exports the createServer
function, which you can call programmatically to apply extra middleware:
Use a different Node.js framework
Anchor link to section titled "Use a different Node.js framework"If you want to use a different Node.js framework like Express or Fastify, then complete the following steps:
Create a new server entry point (for example,
server.js
) and importhydrogenMiddleware
:Update the scripts in
package.json
to specify your new entry point. If the scripts are located in<root>/server.js
, then the changes would look like the following:Run the server bundle:
Use App.server.jsx
as the server entry point
Anchor link to section titled "Use App.server.jsx as the server entry point"If your server isn't compatible with Connect middleware or you're deploying to a serverless platform, then you can directly use the App.server.jsx
file as the server entry point.
Update the scripts in package.json
to specify your new entry point:
This exposes a handleRequest
function that can be imported in your server or serverless function:
Deploy to Docker
Anchor link to section titled "Deploy to Docker"You can deploy your project to any platform that supports Docker-based hosting, like Google Cloud Run, Fly.io, and Heroku. If you've generated a Node.js server, then you can run it inside a Docker container.
Install Docker.
Add a Docker file to the root of your project:
Run Docker inside your app directory by executing the following commands:
The production version of your app will be running at http://localhost:8080.
Deploy to Cloudflare Workers
Anchor link to section titled "Deploy to Cloudflare Workers"You can deploy your Hydrogen app to Cloudflare Workers, a serverless application platform. For the Cloudflare Workers' Cache API to work, you need to meet the following requirements:
- You have a Cloudflare domain. The domain can't be
worker.dev
, because Cloudflare owns this domain. - You have a DNS record for the Cloudflare domain. For example,
A example.dev 192.0.2.1 Proxied
. - You have a worker route that points to the Cloudflare domain.
Create a
wrangler.toml
file in the root of your project.For more information about the configurable properties in the
wrangler.toml
file, refer to Cloudflare's configuration and compatibility dates documentation.Your static files are now uploaded to Workers KV.
Install Cloudflare's KV asset handler:
Create a new Worker entry file (for example,
worker.js
) in your project:Update
package.json
to specify the new Worker entry point. If the entry point is in<root>/worker.js
, then the changes look like the following:Deploy your project with Wrangler:
Deploy to Netlify
Anchor link to section titled "Deploy to Netlify"To learn how to deploy your Hydrogen app to Netlify, refer to Hydrogen on Netlify.