-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-with-env.js
More file actions
32 lines (25 loc) · 851 Bytes
/
test-with-env.js
File metadata and controls
32 lines (25 loc) · 851 Bytes
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
// Load environment explicitly
require('fs').readFileSync('.env', 'utf8').split('\n').forEach(line => {
const [key, value] = line.split('=');
if (key && value) {
process.env[key] = value.replace(/"/g, '');
}
});
const { Client } = require('pg');
console.log('DATABASE_URL:', process.env.DATABASE_URL);
async function testConnection() {
const client = new Client({
connectionString: process.env.DATABASE_URL
});
try {
await client.connect();
console.log('✅ Direct PostgreSQL connection successful');
const result = await client.query('SELECT COUNT(*) FROM organizations');
console.log('✅ Organizations table query successful, count:', result.rows[0].count);
await client.end();
} catch (error) {
console.error('❌ Connection failed:', error.message);
process.exit(1);
}
}
testConnection()