-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-db-connection.js
More file actions
33 lines (30 loc) · 1.08 KB
/
test-db-connection.js
File metadata and controls
33 lines (30 loc) · 1.08 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
require('dotenv').config();
const { Client } = require('pg');
const client = new Client({
host: process.env.POSTGRES_HOST || 'localhost',
port: parseInt(process.env.POSTGRES_PORT || '5432'),
database: process.env.POSTGRES_DB || 'telegram_event_bot',
user: process.env.POSTGRES_USER || 'stj',
password: process.env.POSTGRES_PASSWORD || '',
});
console.log('Connection settings:', {
host: process.env.POSTGRES_HOST || 'localhost',
port: parseInt(process.env.POSTGRES_PORT || '5432'),
database: process.env.POSTGRES_DB || 'telegram_event_bot',
user: process.env.POSTGRES_USER || 'stj',
password: process.env.POSTGRES_PASSWORD ? '***' : '',
});
client.connect()
.then(() => {
console.log('Successfully connected to the database');
return client.query('SELECT current_user, current_database()');
})
.then(res => {
console.log('Current user:', res.rows[0].current_user);
console.log('Current database:', res.rows[0].current_database);
return client.end();
})
.catch(err => {
console.error('Error connecting to the database:', err);
process.exit(1);
});