Skip to content

Commit

Permalink
add config
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshuteotia committed Feb 10, 2024
1 parent 0d6a08b commit eeb0664
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import App from './src/app';
import config from "./src/config/config";

const PORT = 3000;
const PORT = config.port;
const app = new App(PORT);

app.startServer();
25 changes: 25 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import developmentConfig from "./development";
import productionConfig from "./production"

export enum EnvironmentStr {
DEVELOPMENT = "development",
TESTING = "testing",
STAGE = "staging",
PRODUCTION = "production",
}

const {ENVIRONMENT} = process.env;
export const production = ENVIRONMENT === EnvironmentStr.PRODUCTION;
export const development = ENVIRONMENT === EnvironmentStr.DEVELOPMENT;

const config = () =>{
if(production){
return productionConfig;
} else {
return developmentConfig;
}
}


export default config();
10 changes: 10 additions & 0 deletions src/config/development.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import merge from "deepmerge";
import production from './production';

const config = {
port : 3000,
debug: true,
} satisfies Record<string,number|boolean>

export default merge(production,config);
6 changes: 6 additions & 0 deletions src/config/production.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = {
port : 3000,
debug: true,
} satisfies Record<string,number|boolean>

export default config;

0 comments on commit eeb0664

Please sign in to comment.