How to config .env files to connect PostgreSQL of local and Vercel storage in Next.js
Unanswered
Deki posted this in #help-forum
DekiOP
Hi, everyone. How can I config .env files to connect PostgreSQL database of local and Vercel storage according to development and production mode in Next.js?
6 Replies
Labrador Duck
make a DB_URL
fill local db details for local dev
While deploying change the env to deployed db url
fill local db details for local dev
While deploying change the env to deployed db url
@Labrador Duck make a DB_URL
fill local db details for local dev
While deploying change the env to deployed db url
DekiOP
thanks. but would you like to give me sample code? i'm started Next.js before a week.
Labrador Duck
Are you using any ORM for connecting to database?
DekiOP
hi @Labrador Duck, sorry to late. yes. i'm using prisma.
DekiOP
this is my files. so i want to use local PostgreSQL databse in development mode and use Vercel storage in production mode. i'm just guessing if i set up .env.development and .env.production files in some way, i can tackle it.
// prisma/schema.prisma
// .env
// prisma/schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL")
directUrl = env("POSTGRES_URL_NON_POOLING")
}
...// .env
POSTGRES_URL=...
POSTGRES_PRISMA_URL=...
POSTGRES_URL_NON_POOLING=...
...Labrador Duck
while deploying like in vercel set different environment variable