-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load configuration data from environment variables
- Loading branch information
1 parent
f898fd5
commit d962016
Showing
5 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class ConfigurationData { | ||
get MongoDBUrl() { | ||
return this.mongoDBUrl; | ||
} | ||
set MongoDBUrl(url) { | ||
this.mongoDBUrl = url; | ||
} | ||
get NodeEnv() { | ||
return this.nodeEnv; | ||
} | ||
set NodeEnv(environment) { | ||
this.nodeEnv = environment; | ||
} | ||
|
||
toString() { | ||
const output = { | ||
MongoDBUrl: this.MongoDBUrl, | ||
NodeEnv: this.NodeEnv, | ||
}; | ||
|
||
return JSON.stringify(output, null, 2); | ||
} | ||
} | ||
|
||
module.exports = ConfigurationData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Environment variable class is responsible for loading environment variables | ||
* from process and/or operating system so it is available to be used in | ||
* this application | ||
*/ | ||
const ConfigurationData = require('../domains/configuration-data'); | ||
|
||
class EnvironmentVariable { | ||
load() { | ||
const configurationData = new ConfigurationData(); | ||
|
||
configurationData.MongoDBUrl = process.env.MONGODB_URL; | ||
configurationData.NodeEnv = process.env.NODE_ENV; | ||
|
||
return configurationData; | ||
} | ||
} | ||
|
||
module.exports = EnvironmentVariable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Configuration { | ||
constructor(options) { | ||
this.configurationAdapter = options.ConfigurationAdapter; | ||
} | ||
|
||
load() { | ||
return this.configurationAdapter.load(); | ||
} | ||
} | ||
|
||
module.exports = Configuration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Configuration { | ||
constructor(options) { | ||
this.configurationInterface = options.ConfigurationInterface; | ||
} | ||
load() { | ||
return this.configurationInterface.load(); | ||
} | ||
} | ||
|
||
module.exports = Configuration; |