Hi I am looking at this example here <https://gith...
# orm-help
j
Hi I am looking at this example here https://github.com/prisma/prisma-examples/tree/latest/javascript/rest-express and wondering if someone has an example where the routes are spread across several files, do you only want to call
const prisma = new PrismaClient()
once? and then reference it throughout the api?
or would you call:
Copy code
const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()
at the top of each file?
a
Only once. And after I pass it in the
req
So I can access to Prisma everywhere with
req.prisma.find...
j
thanks!
a
in my index.ts I am adding this to declare Prisma
Copy code
declare module 'express-serve-static-core' {
  interface Request {
    prisma: PrismaClient
  }
}
and then
Copy code
const prisma = new PrismaClient()
app.use((req: Request, res: Response, next: NextFunction) => {
  req.prisma = prisma
  next()
})
let me know if you found a better approach
💯 1