Loading Depth Study
Preparing your workspace
Secrets should be stored outside source code and exposed only to the components that actually need them.
Applications commonly need database passwords, signing keys, API credentials, and service tokens. These values should not be committed to public source control. Environment variables, secret managers, and deployment platform secret stores are common ways to provide sensitive configuration. Public configuration and server-only secrets should be clearly separated. If a secret is accidentally exposed, it should be rotated rather than simply deleted from the latest source file.
A backend may need a payment provider secret while the frontend only needs a public API URL or non-sensitive configuration.
const databaseUrl = process.env.DATABASE_URL;
const paymentSecret = process.env.PAYMENT_SECRET;
if (!databaseUrl || !paymentSecret) {
throw new Error('Required server configuration is missing');
}The application reads server-side secrets from its runtime environment and fails early when required configuration is missing.