Skip to content

Commit 0a31c19

Browse files
committed
Update config files
1 parent 6c6ee42 commit 0a31c19

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ DB_HOST=localhost
44
DB_USER=root
55
DB_PASS=
66
DB_NAME=dbname
7+
8+
JWT_SECRET=secret
9+
JWT_EXPIRES_IN=90d

src/config/db.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { config } from "dotenv";
22

33
config();
44

5-
export default {
5+
const dbConfig ={
66
HOST: process.env.DB_HOST,
77
USER: process.env.DB_USER,
88
PASSWORD: process.env.DB_PASS,
99
DATABASE: process.env.DB_NAME,
10-
};
10+
};
11+
12+
export default dbConfig;

src/config/server.config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ import { config } from 'dotenv';
22

33
config();
44

5-
export const port = process.env.PORT;
5+
const serverConfig = {
6+
PORT: process.env.PORT,
7+
JWT_SECRET: process.env.SECRET,
8+
JWT_EXPIRES_IN: process.env.EXPIRES_IN
9+
};
10+
11+
export default serverConfig;

src/server.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import app from './app';
2-
import { port } from './config/server.config';
3-
import db from './services/db';
2+
import serverConfig from './config/server.config';
3+
import db from './services/db.service';
4+
5+
const { PORT } = serverConfig;
46

57
const initApp = async () => {
68
try {
@@ -9,8 +11,8 @@ const initApp = async () => {
911
await db.sync({force: true});
1012
console.log("Database connection has been established successfully.");
1113

12-
app.listen(port || 3000, () => {
13-
console.log(`Server running at http://localhost:${port}`);
14+
app.listen(PORT || 3000, () => {
15+
console.log(`Server running at http://localhost:${PORT}`);
1416
});
1517
} catch (error) {
1618
console.error("Unable to connect to the database:", error);

0 commit comments

Comments
 (0)