Skip to content

Commit

Permalink
Merge pull request #383 from lenneTech/develop
Browse files Browse the repository at this point in the history
Add env path to getEnvironmentConfig
  • Loading branch information
pascal-klesse authored Dec 18, 2024
2 parents 3921bd6 + ea85edd commit 850ae59
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/common/helpers/config.helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as dotenv from 'dotenv';
import * as path from 'node:path';
import * as process from 'node:process';
import { join } from 'path';

import _ = require('lodash');
Expand Down Expand Up @@ -61,14 +63,14 @@ export function merge(obj: Record<string, any>, ...sources: any[]): any {
* @param options.config config object with different environments as main keys (see config.env.ts) to merge environment configurations into (default: {})
* @param options.defaultEnv default environment to use if no NODE_ENV is set (default: 'local')
*/
export function getEnvironmentConfig(options: { config?: Record<string, any>; defaultEnv?: string }) {
export function getEnvironmentConfig(options: { config?: Record<string, any>; defaultEnv?: string; envPath?: string }) {
const { config, defaultEnv } = {
config: {},
defaultEnv: 'local',
...options,
};

dotenv.config();
dotenv.config({ path: options.envPath || path.resolve(process.cwd(), '.env') });
const env = process.env['NODE' + '_ENV'] || defaultEnv;
const envConfig = config[env] || config.local || {};

Expand Down

0 comments on commit 850ae59

Please sign in to comment.