import * as dotenv from "dotenv" ; import dotenvExpand from "dotenv-expand" ; import * as fs from "fs" ; import * as paths from "./paths" ; const NODE_ENV = process . env . NODE_ENV ; if ( ! NODE_ENV ) { throw new Error ( "The NODE_ENV environment variable is required but was not specified." ) ; } const dotenvFiles = [ `${ paths . dotenv }.${ NODE_ENV }.local` , NODE_ENV === "test" ? "" : `${ paths . dotenv }.local` , `${ paths . dotenv }.${ NODE_ENV }` , paths . dotenv , ] . filter ( ( dotenvFile ) => dotenvFile . length && fs . existsSync ( dotenvFile ) ) ; dotenvFiles . forEach ( ( dotenvFile ) => { dotenvExpand ( dotenv . config ( { path : dotenvFile , } ) ) ; } ) ;