Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add env path to getEnvironmentConfig #383

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading