Initial scaffold
This commit is contained in:
17
packages/shared/src/config/env.js
Normal file
17
packages/shared/src/config/env.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// A simple utility to load environment variables from a .env file
|
||||
// Each service calls this at startup to load its configuration
|
||||
|
||||
function getEnv(key, defaultValue){
|
||||
const value = process.env[key];
|
||||
|
||||
//check if the desired value exists, if not check if a default value was provided, if not throw an error
|
||||
if (value === undefined) {
|
||||
if (defaultValue === undefined) {
|
||||
throw new Error(`Missing required environment variable: ${key}`);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
module.exports = {getEnv};
|
||||
3
packages/shared/src/index.js
Normal file
3
packages/shared/src/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const {getEnv} = require('./config/env');
|
||||
|
||||
module.exports = {getEnv};
|
||||
Reference in New Issue
Block a user