Skip to main content
Glama
loadEnvFile.ts911 B
import { existsSync } from 'node:fs'; import dotenv from 'dotenv'; const DEFAULT_ENV = process.env.NODE_ENV ?? 'development'; export type LoadEnvFileOptions = { env?: string; envFile?: string; }; export const getEnvFilePath = ( env: string = process.env.NODE_ENV ?? 'development', envFile?: string ): string | undefined => { const envFiles = envFile ? [envFile] : [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env']; return envFiles.find(existsSync); // Returns the first existing env file }; export const loadEnvFile = (options?: Partial<LoadEnvFileOptions>) => { const env = options?.env ?? DEFAULT_ENV; const envFiles = options?.envFile ? [options.envFile] : [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env']; const result = {}; dotenv.config({ path: envFiles, processEnv: result, }); return result; // Return the parsed env object };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server