Skip to content

Commit b686dfb

Browse files
committed
feat(templates): add config file that contains all env vars
1 parent a838635 commit b686dfb

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const config = {
2+
host: process.env.HOST ?? 'localhost',
3+
port: +(process.env.PORT ?? '9000'),
4+
};
5+
6+
export default config;

generators/app/templates/src/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@ import { MyError } from '@boringcodes/utils/error';
22
import errorHandler from '@boringcodes/utils/errorHandler';
33
import logger from '@boringcodes/utils/logger';
44

5+
import config from './config';
56
import app from './app';
67

7-
// declare env vars
8-
const host =
9-
process.env.HOST !== null && process.env.HOST !== undefined
10-
? process.env.HOST
11-
: 'localhost';
12-
const port =
13-
process.env.PORT !== null && process.env.PORT !== undefined
14-
? +process.env.PORT
15-
: 9000;
16-
178
// start app
18-
app.listen(port, host, (err: MyError) => {
9+
app.listen(config.port, config.host, (err: MyError) => {
1910
if (err !== null && err !== undefined) {
2011
throw err;
2112
}
2213

23-
logger.info(`> App started at http://${host}:${port}`);
14+
logger.info(`> App started at http://${config.host}:${config.port}`);
2415
});
2516

2617
// handle unhandled promise

0 commit comments

Comments
 (0)