<https://www.prisma.io/docs/guides/performance-and...
# orm-help
d
https://www.prisma.io/docs/guides/performance-and-optimization/connection-management#prevent-hot-reloading-from-creating-new-instances-of-prismaclient --- the “global Prisma” example does not work any more - global variables under typescript; NodeJS.Global is not a thing anymore
✅ 1
a
Hey Dave! Thanks for pointing that out, I’ll create an issue to get the docs changed. In the meantime, this might be a suitable alternative.
Copy code
import { PrismaClient } from '@prisma/client';

let prisma: PrismaClient;

if (process.env.NODE_ENV === "production") {
  prisma = new PrismaClient();
} else {
  let globalWithPrisma = global as typeof globalThis & {
    prisma: PrismaClient;
  };
  if (!globalWithPrisma.prisma) {
    globalWithPrisma.prisma = new PrismaClient();
  }
  prisma = globalWithPrisma.prisma;
}

export default prisma;