-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-env.js
More file actions
86 lines (72 loc) · 3.26 KB
/
debug-env.js
File metadata and controls
86 lines (72 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* Environment Variable Debugger
* Shows what's actually being loaded from .env
*/
require('dotenv').config();
console.log('\n═══════════════════════════════════════════════════════════════');
console.log(' ENVIRONMENT VARIABLE DEBUG');
console.log('═══════════════════════════════════════════════════════════════\n');
const vars = [
'DATABASE_URL',
'SUPABASE_URL',
'REDIS_URL',
'OPENAI_API_KEY',
];
vars.forEach(varName => {
const value = process.env[varName];
const exists = !!value;
const length = value ? value.length : 0;
console.log(`${varName}:`);
console.log(` Exists: ${exists ? '✅ YES' : '❌ NO'}`);
console.log(` Length: ${length} characters`);
if (value) {
// Show first/last 10 chars to help debug without exposing full value
const start = value.substring(0, 15);
const end = value.substring(value.length - 10);
console.log(` Preview: ${start}...${end}`);
// Check for common issues
if (value.startsWith(' ') || value.endsWith(' ')) {
console.log(` ⚠️ WARNING: Has leading/trailing spaces!`);
}
if (value.includes('\n')) {
console.log(` ⚠️ WARNING: Contains newline characters!`);
}
if (value.startsWith('"') || value.startsWith("'")) {
console.log(` ⚠️ WARNING: Wrapped in quotes (might be the issue!)`);
}
}
console.log('');
});
console.log('═══════════════════════════════════════════════════════════════\n');
// Try to parse DATABASE_URL specifically
if (process.env.DATABASE_URL) {
console.log('DATABASE_URL Analysis:');
const url = process.env.DATABASE_URL;
try {
const urlObj = new URL(url);
console.log(` Protocol: ${urlObj.protocol}`);
console.log(` Host: ${urlObj.hostname}`);
console.log(` Port: ${urlObj.port}`);
console.log(` Database: ${urlObj.pathname}`);
console.log(` ✅ URL is valid!\n`);
} catch (e) {
console.log(` ❌ ERROR: Invalid URL format`);
console.log(` ${e.message}\n`);
}
} else {
console.log('❌ DATABASE_URL not found in environment!\n');
console.log('Common issues:');
console.log(' 1. Variable name typo (check for spaces, case)');
console.log(' 2. .env file not in project root');
console.log(' 3. Value wrapped in quotes when it shouldn\'t be');
console.log(' 4. Extra spaces before/after the variable name or value');
console.log(' 5. Missing = sign\n');
console.log('Correct format:');
console.log(' DATABASE_URL=postgresql://...\n');
console.log('NOT:');
console.log(' DATABASE_URL = postgresql://... (spaces around =)');
console.log(' DATABASE_URL="postgresql://..." (quoted)');
console.log(' DATABASE_URL =postgresql://... (space before =)\n');
}
console.log('═══════════════════════════════════════════════════════════════\n');