Closed py660 closed 11 months ago
Their dashboard actually has ready connection params for this libary if you choose node.js
under connection details ;)
I do like a single url instead of their setup with many env vars, so you can also try replacing in this url with your details:
`postgres://${ PGUSER }:${ PGPASSWORD }@${ PGHOST }/${ PGDATABASE }?sslmode=require&options=project%3D${ ENDPOINT_ID }`
The full options setup they provide looks like this:
// Do not expose your Neon credentials to the browser
// .env
PGHOST=...
PGDATABASE=...
PGUSER=...
PGPASSWORD=...
ENDPOINT_ID=...
// app.js
const postgres = require('postgres');
require('dotenv').config();
let { PGHOST, PGDATABASE, PGUSER, PGPASSWORD, ENDPOINT_ID } = process.env;
const sql = postgres({
host: PGHOST,
database: PGDATABASE,
username: PGUSER,
password: PGPASSWORD,
port: 5432,
ssl: 'require',
connection: {
options: `project=${ENDPOINT_ID}`,
},
});
async function getPgVersion() {
const result = await sql`select version()`;
console.log(result);
}
getPgVersion();
tysm!
Im trying to use neonDB in a project, but the following error keeps bugging me and blocks progress:
what can i do to fix? I've tried putting the endpoint thing in the parameter, and in the password.