`
These variables are only available locally in MiniOxygen
SESSION_SECRET="foobar"
PUBLIC_STOREFRONT_API_TOKEN="3b580e70970c4528da70c98e097c2fa0"
PUBLIC_STORE_DOMAIN="hydrogen-preview.myshopify.com"
`
i have this .env file in root of my project(created by npm create @shopify/hydrogen@latest)
How to access variables in this .env file? For example i have config
config.ts
`
const builderHost = 'https://example.com';
const Config = {
apiKey: process.env.API_KEY ?? '',
builderWelcomeUrl: `${builderHost}/share/xxxxxxx`,
};
export default Config;
` (also i added API_KEY variable in .env file)
process.env.API_KEY ----> I gain this error: ReferenceError: process is not defined
I'm trying to get API_KEY from .env, write it to config.ts file and use it in my app
I want to write API_KEY in my config.ts file and use it in my app
If you want to access your public environment variables outside component scope, you may do this like this on root loader:
Now in your
config.tsfile you may update like this:Reference: Environment Variables