import * as dotenv from 'dotenv';
dotenv.config();
const env: string = process.env.NODE_ENV || 'development';
export const dynamicConfig = async () => {
const data = await import('./config.' + env);
console.log('data');
return data;
};
from my app.ts
import * as customConfig from '../../config';
class App {
public app: express.Application;
private host: string = process.env.IP || process.env.ADMIN_HOST || dynamicConfig.get('web.host');
private port: number = parseInt(process.env.PORT, 10) || parseInt(process.env.ADMIN_PORT, 10) || dynamicConfig.get('web.port');
private mysql = MySql.getInstance();
constructor(private readonly config: AppConfig) {
this.app = express();
this.initializeInfoLoggingHandling();
console.log(customConfig)
}
this console.log printing
{ customConfig: [Function (anonymous)] }
but it's supposed to print some array. I am just trying to load my configuration dynamically.