Environment variables
Environment variables enable you to load different values in your app depending on the environment it runs in. This guide describes the environment variables used in the demo-store
and hello-world
templates.
When you create a new Hydrogen app using the demo-store
or hello-world
templates, you should provide the following environment variables to your app:
PUBLIC_STOREFRONT_API_TOKEN
: The public access token for the Storefront API.PRIVATE_STOREFRONT_API_TOKEN
: The private access token for the Storefront API.PUBLIC_STOREFRONT_API_VERSION
(optional): The Storefront API version. Defaults to the version of the Storefront API used by Hydrogen.PUBLIC_STORE_DOMAIN
: The domain of the store used to communicate with the Storefront API.SESSION_SECRET
: A secret used to sign session cookies. Refer to the Remix documentation on using sessions for more information.
The Hydrogen channel automatically creates and populates these environment variables when you create a new storefront hosted on Oxygen.
The Headless channel also generates public and private Storefront API tokens when you create a new storefront.
When developing locally, you can store these variables in a .env
file in the root of your project. The following is an example:
When deploying to a hosting environment, you can store these variables in the hosting environment. For example, if you're deploying to Oxygen, then you can store these variables as Oxygen environment variables.
To access environment variables in your Hydrogen app, refer to the Remix documentation for environment variables.
- Learn how to deploy your Hydrogen storefront to Oxygen and other runtimes.