Has anyone used dotenv-cli with prisma?
# orm-help
a
Has anyone used dotenv-cli with prisma?
n
yup
a
I’m having issues were my environment variables are returning undefined. Do I need to run an specific command to set them?
a
Copy code
const dotenv = require('dotenv');
dotenv.load()
a
even for the cli?
a
Oh, missed the cli part
a
All good, im trying to run it from cli without any luck
n
how are you reading the env vars in your code and how are you setting them in the CLI
a
process.env.PRISMA_SECRET
in my scripts I have :
"start": "dotenv -- nodemon -e ts,graphql -x ts-node src/index.ts"
"dev": "npm-run-all --parallel start playground"
so I run in my cli
yarn run dev
n
how does your
.env
file look like?
a
NODE_ENV=“dev” PRISMA_STAGE=“dev” PRISMA_ENDPOINT=“http://localhost:4466/” PRISMA_CLUSTER=“local” PRISMA_SECRET=“mysecret12345” APP_SECRET=“jwtsecret12345"
n
and when you run
console.log(process.env.PRISMA_SECRET)
, it prints
undefined
?
a
correct
I was also trying with this script
"prisma-deploy": "prisma deploy --env-file /config/.env.dev"
n
oh. So you don't have an
.env
file, but your file is in
./config/.env.dev
?
a
Correct
n
ok 🙂
in your
package.json
, replace
dotenv
with
dotenv -e ./config/.env.dev
a
for which one?
n
for
prisma deploy
, an env var file in a subdirectory is currently not supported: https://github.com/prismagraphql/prisma/issues/1701
the
start
script you shared above.
a
Aweesome thanks!
It worked beautifully thanks Nilan!
👌 1
n
Generally, all dotenv tooling uses
.env
as a default file, if you have a different file name you need to specify it.
a
This is a great lesson thanks 🙂