Can't access env variables for postgres database

I’m trying to set up a vercel project with a postgres database, but I can’t seem to access the env variables and actually access the database. I’m in the root directory, and I run vercel env pull .env.development.local which makes my directory look like this:

webapp
-.env.development.local
-src/
--app/
---api/
----create-project/
-----route.ts

In my route.ts file, this is the code I have:

import { sql } from '@vercel/postgres';

export default async function createProject() {
    console.log({
        POSTGRES_URL: process.env.NEXT_PUBLIC_POSTGRES_URL,
        POSTGRES_URL_NON_POOLING: process.env.NEXT_PUBLIC_POSTGRES_URL_NON_POOLING
    });
}

But the console.log returns undefined for both POSTGRES_URL and POSTGRES_URL_NON_POOLING. I’m very new to Vercel and NextJS, any ideas on how to fix this? To start local development, I run vercel dev

Hi

Do you have NEXT_PUBLIC_POSTGRES_URL defined in your project or just POSTGRES_URL?

See also: next.config.js Options: env | Next.js

@sweng411group14-gmai Beloe are the variables generated

POSTGRES_URL
POSTGRES_PRISMA_URL
POSTGRES_URL_NON_POOLING
POSTGRES_USER
POSTGRES_HOST
POSTGRES_PASSWORD
POSTGRES_DATABASE

to verify if you are using the correct variables can you try running below command from the CLI and check the results.

vercel env pull .env.development.local

Or Just

 vercel env pull

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.