Created
September 4, 2022 18:34
-
-
Save GautamPanickar/6ab678d61274eba8a2546ba349323f3f to your computer and use it in GitHub Desktop.
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
import * as Dotenv from 'dotenv'; | |
import SecretKeys from '../types/secretkeys'; | |
const secretValues: SecretKeys = { | |
ENVIRONMENT: '', | |
PORT: 0, | |
DB_NAME: 'noname.db' | |
}; | |
class Secret { | |
/** | |
* Gets the secret. | |
*/ | |
public static get Secret(): SecretKeys { | |
// Loading environment variables from .env file | |
Dotenv.config({ path: `${__dirname}/../../.env` }); | |
secretValues.ENVIRONMENT = process.env['NODE_ENV']; | |
secretValues.DB_NAME = process.env['DB_NAME']; | |
secretValues.PORT = parseInt(process.env['PORT']); | |
if (!secretValues.DB_NAME) { | |
console.log('No database name provided. Set DB_NAME environment variable.'); | |
process.exit(1); | |
} | |
if (!secretValues.PORT) { | |
console.log('Server listening port not set.'); | |
process.exit(1); | |
} | |
return secretValues; | |
} | |
} | |
export default Secret.Secret; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment