NeonN
Neon12mo ago
19 replies
worthy-rose

Failing to connect to the DB.

I have a nodejs application and I have been trying to connect using the conncetion string but I have just been getting errors

Here is the code

const { Client } = require("pg"); require("dotenv").config(); const SQL = CREATE TABLE IF NOT EXISTS messages(id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, username VARCHAR(255),message VARCHAR(255));


INSERT INTO messages (username,message)
VALUES ('Yandhi','Hello')

; async function main() { console.log( "seeding", ); const client = new Client({ connectionString: process.env.DATABASE_URL, connectionTimeoutMillis: 10000, ssl: { rejectUnauthorized: false }, idle_in_transaction_session_timeout: 10000, }); await client.connect(); await client.query(SQL); await client.end(); } main();
question.png
Was this page helpful?