UNPKG

env-validate

Version:

Validates your environment variables are set at runtime.

17 lines (10 loc) 631 B
const fs = require('fs'); const path = require('path'); const MAX_LEVELS = 10; const ERROR_MESSAGE_MAX_LEVELS = `No '.env.template' file could be found in one of ${MAX_LEVELS} direct levels above the currrent folder. Please consider passing the absolute path of your template file as argument.`; const findTemplatePath = (dirPath = __dirname, currentLevel = 0) => { if (currentLevel >= MAX_LEVELS) throw ERROR_MESSAGE_MAX_LEVELS; const filePath = `${dirPath}.env.template`; return fs.existsSync(filePath) ? filePath : findTemplatePath(path.join(dirPath, '../'), currentLevel + 1); }; module.exports = findTemplatePath;