UNPKG

@buka/nestjs-config

Version:
17 lines (16 loc) 588 B
import { Logger } from '@nestjs/common'; import { readFile } from 'fs/promises'; import { fsExist } from '../utils/fs-exists.js'; import { parse } from 'smol-toml'; export function tomlFileLoader(filepath, encoding = 'utf-8') { return async (options) => { if (!await fsExist(filepath)) { if (!options.suppressWarnings) { Logger.warn(`env file not found: ${filepath}`, '@buka/nestjs-config'); } return {}; } const content = await readFile(filepath); return parse(content.toString(encoding)); }; }