Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(config): keep dotenv from printing its load banner at boot

Yudhi Armyndharis88713e13c5d6
diff --git a/src/config/load-env.spec.ts b/src/config/load-env.spec.ts
index cbfb54ecb..3c2a88474 100644
--- a/src/config/load-env.spec.ts
+++ b/src/config/load-env.spec.ts
@@ -71,6 +71,24 @@ describe('loadEnvironment', () => {
expect(workerConnectionOptions().host).toBe('host-from-process-env');
});
+ // dotenv 17 prints an "injected env ... // tip: ..." line to stdout on every load unless told to be
+ // quiet. It bypasses the logger, so in production it lands as plain text in the JSON log stream.
+ it.each<[string, Record<string, string>]>([
+ [
+ 'a saved configuration',
+ { '.env': 'REDIS_HOST=redis.internal\n', 'data/.env.generated': 'QUEUE_ENABLED=false\n' },
+ ],
+ ['a first run', { '.env': 'REDIS_HOST=redis.internal\n' }],
+ ])('keeps dotenv from printing its own load banner on %s', (_case, files) => {
+ delete process.env.DOTENV_CONFIG_QUIET;
+ makeTempCwd(files);
+ const log = jest.spyOn(console, 'log').mockImplementation(() => undefined);
+
+ runLoader();
+
+ expect(log.mock.calls.map(args => args.join(' '))).not.toContainEqual(expect.stringContaining('injected env'));
+ });
+
// Older .env templates shipped DATABASE_SSL=false, and compose forwards it, so it silently outranks
// TLS turned on in the dashboard. The override stands, but the boot log names both values.
it('warns when a pinned database TLS setting differs from the one saved in the dashboard', () => {
diff --git a/src/config/load-env.ts b/src/config/load-env.ts
index 144823b07..1372524df 100644
--- a/src/config/load-env.ts
+++ b/src/config/load-env.ts
@@ -57,7 +57,7 @@ export function loadEnvironment(): void {
// 2. User-managed .env (does not override real process env)
if (fs.existsSync(userEnvPath)) {
console.log('[Bootstrap] Loading .env from:', userEnvPath);
- dotenv.config({ path: userEnvPath, override: false });
+ dotenv.config({ path: userEnvPath, override: false, quiet: true });
}
// Snapshot the layers that will SHADOW the dashboard-saved file — process env plus the .env just
@@ -69,7 +69,7 @@ export function loadEnvironment(): void {
// 3. Dashboard-saved config (does not override .env or process env)
if (fs.existsSync(generatedEnvPath)) {
console.log('[Bootstrap] Loading saved configuration from:', generatedEnvPath);
- const { parsed = {} } = dotenv.config({ path: generatedEnvPath, override: false });
+ const { parsed = {} } = dotenv.config({ path: generatedEnvPath, override: false, quiet: true });
// Compose forwards DATABASE_SSL*, and templates older than 0.18 set DATABASE_SSL=false in .env, so
// a stale line can outrank TLS turned on in the dashboard. The override stands; the log names it.
for (const key of ['DATABASE_SSL', 'DATABASE_SSL_REJECT_UNAUTHORIZED']) {
@@ -106,7 +106,7 @@ STORAGE_LOCAL_PATH=./data/media
`;
writeSecretFile(generatedEnvPath, minimalConfig);
console.log('[Bootstrap] Created default configuration at:', generatedEnvPath);
- dotenv.config({ path: generatedEnvPath, override: false });
+ dotenv.config({ path: generatedEnvPath, override: false, quiet: true });
}
}