@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
17 lines (15 loc) • 343 B
text/typescript
/**
* Returns true if load was successful
*/
export function loadEnvFileIfExists(path = '.env'): boolean {
try {
process.loadEnvFile(path)
return true
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
// gracefully ignore that the file does not exist
return false
}
throw err
}
}