#Need help with pogresql

20 messages · Page 1 of 1 (latest)

open oriole
#

I think you need to initialize dotenv on top of your file

#

So env vars can be used here

twilit kraken
#

ohh

#

🤦‍♂️🤦‍♂️

#

@open oriole

#

It's still the same

#
const { Client } = require("pg");
const dotenv = require("dotenv");

console.log(process.env.DATABASE_URL);

const client = new Client(process.env.DATABASE_URL);

(async () => {
    await client.connect();
    try {
        const results = await client.query("SELECT NOW()");
        console.log(results);
    } catch (err) {
        console.error("error executing query:", err);
    } finally {
        client.end();
    }
})();
#

console.log(process.env.DATABASE_URL); -> undefined

open oriole
#

I said initialize

#

not just require

twilit kraken
#

how????

open oriole
#

const dotenv = require("dotenv");

Change to

require('dotenv').config();

twilit kraken
#

THANKYOUU!!!!

open oriole
#

and do it on top of your file

twilit kraken
#

I've been trying the since eternity

open oriole
#

but that is shown as one of the first things in dotenv documentation

#

If not sure -> read docs 🙂

twilit kraken
#

true

#

I thought it was error with the DB

open oriole
#

it's ok, simplest things are often missed