Bird
0
0

Why might this PrismaService fail to connect to the database?

medium📝 Debug Q7 of 15
NestJS - Database with Prisma
Why might this PrismaService fail to connect to the database?
@Injectable()
export class PrismaService extends PrismaClient {
  constructor() {
    super({ datasources: { db: { url: process.env.DATABASE_URL } } });
  }
}
APrismaClient cannot be extended in NestJS
BMissing async keyword in constructor
CDATABASE_URL environment variable is not set or incorrect
Dsuper() must be called without parameters
Step-by-Step Solution
Solution:
  1. Step 1: Check environment variable usage

    If process.env.DATABASE_URL is missing or wrong, connection fails.
  2. Step 2: Validate other options

    Extending PrismaClient is valid; constructor cannot be async; super() accepts config.
  3. Final Answer:

    DATABASE_URL environment variable is not set or incorrect -> Option C
  4. Quick Check:

    Missing or wrong DATABASE_URL causes connection failure [OK]
Quick Trick: Always verify DATABASE_URL is set correctly in environment [OK]
Common Mistakes:
  • Thinking PrismaClient cannot be extended
  • Trying to make constructor async
  • Ignoring environment variable setup

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes