@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
25 lines (24 loc) • 607 B
JavaScript
import { fs2 } from '../fs/fs2.js';
/**
* @example
*
* const {a, b} = requreEnvKeys(['a', 'b'])
*
* Will throw if any of the passed keys is not defined.
*/
export function requireEnvKeys(...keys) {
// oxlint-disable-next-line unicorn/no-array-reduce
return keys.reduce((r, k) => {
const v = process.env[k];
if (!v)
throw new Error(`${k} env variable is required, but missing`);
r[k] = v;
return r;
}, {});
}
/**
* @deprecated use fs2.requireFileToExist
*/
export function requireFileToExist(filePath) {
fs2.requireFileToExist(filePath);
}