Skip to content

Commit c958ac9

Browse files
committed
fix for hardcoded defaults #3
1 parent 8985832 commit c958ac9

File tree

3 files changed

+764
-8
lines changed

3 files changed

+764
-8
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
DB_HOST=localhost
2-
DB_USER=root
2+
DB_USER=
33
DB_PASS=
44
DB_DATABASE=twitter_clone

dbConfig.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ const dotenv = require("dotenv")
33
dotenv.config();
44

55
// Get the Host from Environment or use default
6-
const host = process.env.DB_HOST || 'localhost';
6+
const host = process.env.DB_HOST;
77

88
// Get the User for DB from Environment or use default
9-
const user = process.env.DB_USER || 'root';
9+
const user = process.env.DB_USER;
1010

1111
// Get the Password for DB from Environment or use default
12-
const password = process.env.DB_PASS || '';
12+
const password = process.env.DB_PASS;
1313

1414
// Get the Database from Environment or use default
15-
const database = process.env.DB_DATABASE || 'twitter_clone';
15+
const database = process.env.DB_DATABASE;
16+
17+
if(!host || !user || !password || !database) {
18+
console.error('Needed credentials not found! Please create .env file from .env.example and fill the values');
19+
process.exit(1);
20+
}
1621

1722
module.exports = { host, user, password, database };

0 commit comments

Comments
 (0)