What's the proper way to handle environment variables? #1348
Unanswered
drewdecarme
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I wanted to see if there was a specific opinion on how to handle environment variables for both development and production builds of a nexus app.
There seems to be a lot of documentation surrounding environment variables for Prisma, specifically for opinions on the
.envfile being co-located with the Prisma schema. Or there is also more documentation on how to use a.envfile that isn't co-located with your Prisma schema.I know Prisma is only through Nexus using a plugin, but depending upon the opinions of the nexus team, the convention that Prisma established might conflict with what other's are using.
If you're anything like me, you typically use a mono-repo for a full-stack solution, and like to keep your
.envfiles at the root of your repository and usedotenvto import them. I'm finding that this is problematic atnexus buildtime where the reflection process "runs" my code but doesn't have access to the environment variables that it might need.Here's a specific example.
I'm using stripe and their recommended way of instantiating their JS SDK is via the following:
Another example for using SendGrid:
When
nexus buildis run, all of my environment files, including this one aren't initialized. It's only after the reflection process (I believe, kind of why I'm asking this question) that the environment variables are included in the solution viadotenvat myapp.tsentry point.In SendGrid's case, I'm getting the below error:
API key does not start with "SG.". 1440 ● nexus:plugin:nexusPluginPrisma Running generatorsAnd I'm almost 100% sure that it's because that environment variable doesn't exist... at least at first it doesn't exist.
This long-winded question is more or less asking if first, this is a "correct" way in the eyes of the nexus team, and second if there is a "more" correct way of doing this?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions