adds nodeEnv to src/config/config
This commit is contained in:
		@@ -2,15 +2,20 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export interface IConfig {
 | 
					export interface IConfig {
 | 
				
			||||||
  mongodbUri: string;
 | 
					  mongodbUri: string;
 | 
				
			||||||
 | 
					  nodeEnv: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Config implements IConfig {
 | 
					class Config implements IConfig {
 | 
				
			||||||
  private static instance: Config;
 | 
					  private static instance: Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public readonly mongodbUri: string;
 | 
					  public readonly mongodbUri: string;
 | 
				
			||||||
 | 
					  public readonly nodeEnv: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private constructor() {
 | 
					  private constructor() {
 | 
				
			||||||
    this.mongodbUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/dailytrends';
 | 
					    this.mongodbUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/dailytrends';
 | 
				
			||||||
 | 
					    this.nodeEnv = process.env.NODE_ENV || 'development';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.validateConfig();
 | 
					    this.validateConfig();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -26,6 +31,18 @@ class Config implements IConfig {
 | 
				
			|||||||
      throw new Error('MONGODB_URI is required');
 | 
					      throw new Error('MONGODB_URI is required');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public isDevelopment(): boolean {
 | 
				
			||||||
 | 
					    return this.nodeEnv === 'development';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public isProduction(): boolean {
 | 
				
			||||||
 | 
					    return this.nodeEnv === 'production';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public isTest(): boolean {
 | 
				
			||||||
 | 
					    return this.nodeEnv === 'test';
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const config = Config.getInstance();
 | 
					export const config = Config.getInstance();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user