How to reference a variable inside a dotenv (.env) file
Use another variable inside your .env files.
Mike Griffiths
.env
files are now the norm for defining environment variables. Sometimes though, especially in larger projects, they can contain hundreds of lines.
In these cases you may need to reference another, already defined variable from within your dotenv/.env file.
For example, let's say I define my app's URL at the top of the file:
APP_URL=https://example.com
What if a package requires me to set up a webhook? Clearly that's different per environment. So you'll need to reference the APP_URL
in there. Here's how to do it.
Wrap the URL in ${}
. For example: ${APP_URL}/webhooks
.
A full example is below:
APP_URL=https://example.domain
SHOPIFY_WEBHOOKS="${APP_URL}/shopify/webhook"
In this example SHOPIFY_WEBHOOKS
is set to https://example.domain/shopify/webhook
.
Hope this is of some use.