Use prisma globally in api routes
I have a question, is it possible to use the prisma client globally without having to import it everytime? I'm using Prisma + Turso so there's a bit more than just two lines of code to use the prisma client so adding it to every api file is a bit tiring, is there a way to make it available as a util/helper globally?
what is the best way to do it?
3 Replies
exports in
server/utils/
will be auto-imported. otherwise use the imports
field in nuxt.config.ts
to specify your own paths https://nuxt.com/docs/api/nuxt-config#importshttps://nuxt.com/docs/guide/directory-structure/server#server-utilities
it exports a
defineWrappedResponseHandler
thoNuxt
server/ · Nuxt Directory Structure
The server/ directory is used to register API and server handlers to your application.
update: im using it as a
server/utils
, but instead of exporting a handler, i'm just exporting prisma itself :salute: