💾 Archived View for iich.space › src › modules › dotenv › index.ts captured on 2022-03-01 at 16:04:10.

View Raw

More Information

⬅️ Previous capture (2021-12-03)

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

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;
    });
};