Skip to main content
Glama
loadEnv.ts1.19 kB
import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; export default function loadEnvFromDotenv() { try { const candidates: string[] = []; candidates.push(path.join(process.cwd(), ".env")); try { const here = path.dirname(fileURLToPath(import.meta.url)); candidates.push(path.resolve(here, "../.env")); candidates.push(path.resolve(here, "../../.env")); } catch {} const envPath = candidates.find(p => fs.existsSync(p)); if (!envPath) return; const content = fs.readFileSync(envPath, "utf8"); for (const rawLine of content.split(/\r?\n/)) { const line = rawLine.trim(); if (!line || line.startsWith("#")) continue; const eq = line.indexOf("="); if (eq === -1) continue; const key = line.slice(0, eq).trim(); let value = line.slice(eq + 1).trim(); if ( (value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")) ) { value = value.slice(1, -1); } if (!(key in process.env)) { process.env[key] = value; } } } catch (err) { console.error("Error ENV", err); } }

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/tndfame/mcp_management'

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