21 lines
568 B
TypeScript
21 lines
568 B
TypeScript
import { Client } from 'pg';
|
|
import 'dotenv/config';
|
|
|
|
async function testConnection() {
|
|
const connectionString = process.env.DATABASE_URL;
|
|
const client = new Client({ connectionString });
|
|
|
|
try {
|
|
console.log("Connecting to:", connectionString?.split('@')[1]);
|
|
await client.connect();
|
|
console.log("Connected successfully!");
|
|
const res = await client.query('SELECT NOW()');
|
|
console.log("Current time from DB:", res.rows[0]);
|
|
await client.end();
|
|
} catch (err) {
|
|
console.error("Connection error:", err.message);
|
|
}
|
|
}
|
|
|
|
testConnection();
|