Question

How to Access Prisma Client from App in Function on DigitalOcean App Platform ?

Hi, I’m having an issue using Prisma with Functions on DigitalOcean’s App Platform. I’ve deployed an app and a function together, and I need to access the Prisma schema and client from the app to the function. I’ve tried multiple approaches, but nothing has worked so far. Is there a solution for this?"


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
December 17, 2024

Hey Jirapat!

This happens because functions in DigitalOcean’s App Platform are isolated from the web services where your main app and Prisma Client reside. This separation means that your function code doesn’t automatically have access to the Prisma Client or schema defined in your web service. Both are indipendant.

What you’ll need to do is to make sure the Prisma Client is bundled directly with your function’s code and that your database connection is correctly configured.

First, make sure the Prisma Client is installed as a dependency in the function’s own package.json. Even though the client might already exist in your main app, functions operate in a separate environment, so they need their own instance.

After adding Prisma to your function’s dependencies, generate the Prisma Client within the function’s directory using npx prisma generate.

You also need to make sure the function has the correct database connection URL. You can do this by setting the DATABASE_URL environment variable for the function, either in the App Spec YAML file or through the DigitalOcean Control Panel. This URL should point to your DigitalOcean Managed Database.

If deploying the Prisma Client with your function becomes too much due to size or complexity, an alternative approach would be to let your main app handle database interactions. You could create a REST API endpoint in your main app for your function to call when it needs to perform database operations. This way, your function can remain lightweight and offload database work to the web service.

Hope this helps!

- Bobby

This comment has been deleted

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Become a contributor for community

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

    New accounts only. By submitting your email you agree to our Privacy Policy

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.