Skip to content

Commit

Permalink
refactor(core): Load dotenv as early as possible (no-changelog) (#10948)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Sep 25, 2024
1 parent 5ce05b3 commit afbe884
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/cli/bin/n8n
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ require('express-async-errors');
require('source-map-support').install();
require('reflect-metadata');

// Skip loading dotenv in e2e tests.
// Also, do not use `inE2ETests` from constants here, because that'd end up code that might read from `process.env` before the values are loaded from an `.env` file.
if (process.env.E2E_TESTS !== 'true') {
// Loading dotenv early ensures that `process.env` is up-to-date everywhere in code
require('dotenv').config();
}

if (process.env.NODEJS_PREFER_IPV4 === 'true') {
require('dns').setDefaultResultOrder('ipv4first');
}
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GlobalConfig } from '@n8n/config';
import convict from 'convict';
import dotenv from 'dotenv';
import { flatten } from 'flat';
import { readFileSync } from 'fs';
import merge from 'lodash/merge';
Expand All @@ -22,8 +21,6 @@ if (inE2ETests) {
process.env.N8N_PUBLIC_API_DISABLED = 'true';
process.env.SKIP_STATISTICS_EVENTS = 'true';
process.env.N8N_SECURE_COOKIE = 'false';
} else {
dotenv.config();
}

// Load schema after process.env has been overwritten
Expand Down

0 comments on commit afbe884

Please sign in to comment.