Skip to content

Instantly share code, notes, and snippets.

@aindong
Created March 10, 2022 08:08
Show Gist options
  • Save aindong/bb2fa5e1ba7bc8557ddd956341177abf to your computer and use it in GitHub Desktop.
Save aindong/bb2fa5e1ba7bc8557ddd956341177abf to your computer and use it in GitHub Desktop.
Importing Prisma Best Practice on Nodejs + Express
import { PrismaClient } from '@prisma/client';
declare global {
// allow global `var` declarations
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
export const prisma =
global.prisma ||
new PrismaClient({
log: ['query']
});
if (process.env.NODE_ENV !== 'production') global.prisma = prisma;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment