#How to use .env variable in config file
2 messages · Page 1 of 1 (latest)
Officially according to the docs, the use of .env variables in the astro.config.mjs file is not supported: https://docs.astro.build/en/guides/configuring-astro/#environment-variables
This might be a workaround, but I have only tested it in development and not in production. I'm also not sure if there are any security concerns with this workaround (like potentially exposing private keys to the client) so use at your own risk.
astro.config.mjs:
import { defineConfig } from 'astro/config';
import * as dotenv from 'dotenv';
dotenv.config();
// You can now access process.env.YOUR_ENV_VAR
export default defineConfig({});
Hat tip: #storyblok message