💾 Archived View for iich.space › src › modules › dotenv › index.ts captured on 2021-12-03 at 14:04:38.

View Raw

More Information

-=-=-=-=-=-=-

import { readFileSync } from 'fs';

import { createLogger } from '@/log';

const log = createLogger();

export default (path = '.env'): void => {
  const data = readFileSync(path);

  data
    .toString()
    .split('\n')
    .map((line) => /(\S*)=(.*)$/.exec(line))
    .filter(<T>(value: T | null): value is T => value !== null)
    .forEach(([, key, value]) => {
      log.debug(`${key} = ${value}`);
      process.env[key] = value;
    });
};