Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

359
Views
How to use multiple .env files in Prisma?

I am working on a nestjs project using Prisma, and I want to use multiple .env files with Prisma. I follow the guide here. According to the guide, I add:

"migratetest:mysql": "dotenv -e .env.test -- npx prisma migrate dev",
"migratedev:mysql": "dotenv -e .env.development -- npx prisma migrate dev"

to my package.json. I run migratetest:mysql to load the .env.test file and do the migration. Then, I run start: dev to start the app. However, the Prisma said:

Error: error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:10
   | 
 9 |   provider = "mysql"
10 |    url      = env("DATABASE_URL")
   | 

It seems that it can not find the .env file in my project (based on the guide, there is no .env file, it should change to .env.test and .env.development)

here is my .env.test:

DATABASE_URL=mysql://root:123456@localhost:3306/test

here is my .env.development:

DATABASE_URL=mysql://root:123456@localhost:3306/dev

please help :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to tell every script you have to use dotenv cli, so your start:dev should look like this:

"start:dev": "dotenv -e .env.development nest start --watch",

However, for me it's not starting the compilation in watch mode, I'm still trying to debug this. Any ideas?

EDIT: I posted this and 2 minutes later I was able to solve my issue :D The final version of the script should look like this:

"start:dev": "dotenv -e .env.development -- nest start --watch",

Reason for the need of two dashes being explained in Prisma docs:

Note: dotenv doesn't pass the flags to the Prisma command by default, this is why the command includes two dashes -- before prisma, making it possible to use flags like --force, --schema or --preview-feature.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!