UNPKG

hins

Version:

[![codecov](https://codecov.io/gh/l-zoy/hins/branch/main/graph/badge.svg)](https://codecov.io/gh/l-zoy/hins) [![GitHub license](https://img.shields.io/github/license/l-zoy/hins)](https://github.com/l-zoy/hins/blob/master/LICENSE) ![node-current](https://i

17 lines (14 loc) 460 B
import { parse } from 'dotenv' import fs from 'fs' export default function withEnv(envPath: string) { // If the path exists // Compare one by one, the existing value will not be overwritten if (fs.existsSync(envPath)) { const parsed = parse(fs.readFileSync(envPath, 'utf-8')) Object.keys(parsed).forEach((key) => { if (!Object.prototype.hasOwnProperty.call(process.env, key)) { process.env[key] = parsed[key] } }) } }