UNPKG

@buka/nestjs-config

Version:
16 lines (15 loc) 558 B
import { Logger } from '@nestjs/common'; import { readFile } from 'fs/promises'; import { fsExist } from '../utils/fs-exists.js'; export function jsonFileLoader(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 JSON.parse(content.toString(encoding)); }; }