Add logic to use env variables

This commit is contained in:
Al366io
2024-01-20 01:59:58 +01:00
parent 35a6e1a19a
commit 4d204bf251
3 changed files with 27 additions and 10 deletions

View File

@ -1,3 +1,7 @@
import { Logger } from "pino";
import dotenv from 'dotenv';
dotenv.config();
/**
* Runs the function `fn`
* and retries automatically if it fails.
@ -23,3 +27,12 @@ export const retry = async <T>(
};
export const sleep = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
export const retrieveEnvVariable = (variableName: string, logger: Logger) => {
const variable = process.env[variableName] || '';
if (!variable) {
logger.error(`${variableName} is not set`);
process.exit(1);
}
return variable;
}