MCPcopy Create free account
hub / github.com/ShipSecAI/studio / loadWorkerEnv

Function loadWorkerEnv

pm2.config.cjs:201–231  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

199
200// Load worker .env file for OpenSearch and other worker-specific variables
201function loadWorkerEnv() {
202 const envPath = path.join(__dirname, 'worker', '.env');
203 const env = {};
204
205 try {
206 if (fs.existsSync(envPath)) {
207 const envContent = fs.readFileSync(envPath, 'utf-8');
208 envContent.split('\n').forEach((line) => {
209 const trimmed = line.trim();
210 // Skip comments and empty lines
211 if (!trimmed || trimmed.startsWith('#')) {
212 return;
213 }
214 const match = trimmed.match(/^([^=]+)=(.*)$/);
215 if (match) {
216 const key = match[1].trim();
217 let value = match[2].trim();
218 // Remove surrounding quotes if present
219 if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
220 value = value.slice(1, -1);
221 }
222 env[key] = value;
223 }
224 });
225 }
226 } catch (err) {
227 console.warn('Failed to load worker .env file:', err.message);
228 }
229
230 return env;
231}
232
233const workerEnv = loadWorkerEnv();
234

Callers 1

pm2.config.cjsFile · 0.85

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected