Developer
Strongly Typed Environment Variables
This project uses TypeScript to provide strong typing for environment variables while keeping the familiar process.env.* syntax.
Usage
Use process.env as you normally would, but now with full TypeScript support:
Benefits
- Type Safety: TypeScript will catch typos and missing environment variables at compile time
- IntelliSense: Get autocomplete suggestions for all available environment variables
- Familiar Syntax: Continue using
process.env.*as you always have - No Runtime Overhead: Pure compile-time type checking with no additional runtime code
Environment Variables
All environment variables are strongly typed in /src/lib/types/env.d.ts.
Available Variables
AGILITY_GUID- Agility CMS GUIDAGILITY_API_FETCH_KEY- Agility CMS fetch API keyAGILITY_API_PREVIEW_KEY- Agility CMS preview API keyAGILITY_SECURITY_KEY- Agility CMS security keyAGILITY_LOCALES- Supported localesAGILITY_SITEMAP- Sitemap nameAGILITY_FETCH_CACHE_DURATION- Cache duration for fetchAGILITY_PATH_REVALIDATE_DURATION- Revalidation durationNEXT_PUBLIC_POSTHOG_KEY- PostHog API key (optional - analytics disabled if not set)NEXT_PUBLIC_POSTHOG_HOST- PostHog host URL (optional - analytics disabled if not set)NODE_ENV- Node environment (strongly typed as 'development' | 'production' | 'test')
Optional Analytics Configuration
The PostHog environment variables are optional. If not configured:
- Analytics tracking is silently skipped
- Feature flags return
undefined(A/B tests use control variant) - The application works normally without any errors
To enable analytics, set both NEXT_PUBLIC_POSTHOG_KEY and NEXT_PUBLIC_POSTHOG_HOST.
Adding New Environment Variables
To add a new environment variable:
- Add it to the
ProcessEnvinterface in/src/lib/types/env.d.ts:
- Add the variable to your
.env.localfile - Restart your TypeScript server for changes to take effect
Type Safety Features
Required vs Optional Variables
NODE_ENV Type Safety
The NODE_ENV variable is strongly typed to only allow valid values:
Migration Complete
All files in the project now use strongly typed process.env.* access with no changes to the existing syntax.