컨텐츠로 건너뛰기

Environment Variables API Reference

이 내용은 아직 번역본이 없습니다.

Added in: astro@5.0.0 Beta

The astro:env API lets you configure a type-safe schema for environment variables you have set. This allows you to indicate whether they should be available on the server or the client, and define their data type and additional properties. For examples and usage instructions, see the astro:env guide.

import {
getSecret,
} from 'astro:env';

Added in: astro@5.0.0 Beta

The getSecret() helper function allows retrieving the raw value of an environment variable by its key.

For example, you can retrieve a boolean value as a string:

import {
FEATURE_FLAG, // boolean
getSecret
} from 'astro:env/server'
getSecret('FEATURE_FLAG') // string | undefined

This can also be useful to get a secret depending on dynamic data, such as from a database or API.

If you need to retrieve environment variables programmatically, we recommend using getSecret() instead of process.env (or equivalent). Because its implementation is provided by your adapter, you won’t need to update all your calls if you switch adapters. It defaults to process.env in dev and build.

기여하기

여러분의 생각을 들려주세요!

GitHub Issue 생성

우리에게 가장 빨리 문제를 알려줄 수 있어요.

커뮤니티