How to get environment variables in a prisma schema

I’m trying to use the .env file to fill in one line of code i.e. DATABASE_URL = ‘xxxx’

But this page is making more confused (https://docs.replit.com/programming-ide/workspace-features/storing-sensitive-information-environment-variables).

In the Secrets pane, I already input

  • key = DATABASE_URL
  • value = xxxx

Now how do I input those in my code? Based on the gif and text, I’m supposed to put process.env.MY_SECRET . But then in Javascript part, I’m supposed to put console.log(process.env.MY_SECRET);

Please please please don’t do gif where it’s too tiny to even see AND it’s not the same as the text. Use video or pics. Also, Sync up the text and gif. THey’re not the same. And the gifs are outdated.

Please help

you refer to it in the code by process.env.DATABASE_URL

1 Like

how do i make it into a string? i keep this error:
error: Expected a string value, but received literal value process.env.DATABASE_URL.

How are you trying to handle it?

what do you mean? you mean what’s the solution?

What is your code doing with that variable, how are you trying to read it, etc. (Code snippet or repl link would be great!)

i’m trying to connect to Prisma. Basically, Prisma has this code in .env:
DATABASE_URL = ‘mysqlxxxxx’

Usually I can call the DATABASE_URL in schema.prisma file with “DATABASE_URL”. But now I’m trying to figure out how to do that.

Did it fail to paste?

i’m trying to connect to Prisma. Basically, Prisma has this code in .env:
DATABASE_URL = ‘mysqlxxxxx’

Usually I can call the DATABASE_URL in schema.prisma file with “DATABASE_URL”. But now I’m trying to figure out how to do that.

The error says:
error: Expected a string value, but received literal value process.env.DATABASE_URL.

I’m not sure how to help you troubleshoot that error without seeing how your code is trying to handle the variable.

the value is ‘mysqlxxxx’

Try just url = process.env.DATABASE_URL.

i got same error:
 npx prisma migrate dev --name init
Prisma schema loaded from prisma/schema.prisma
Error: Prisma schema validation - (get-config wasm)
Error code: P1012
error: Expected a String value, but received literal value process.env.DATABASE_URL.
→ schema.prisma:10
|
9 | provider = “mysql”
10 | url = process.env.DATABASE_URL
|

Validation Error Count: 1
[Context: getConfig]

Prisma CLI Version : 4.12.0

Hmm. I’m not sure as this is not a language I’ve ever touched before, was just an idea.

unfortunately, it didn’t work

I don’t think you can set DATABASE_URL as a Secret. Unless the Replit DB URL secret is different. Can’t remember rn.

1 Like

Oh, I just checked and a prisma schema file is not even js. That is why the tutorial doesn’t work, it is a schema file not a js file. Just do env("DATABASE_URL").

1 Like

didn’t work unfortunately. got this:
Prisma schema loaded from prisma/schema.prisma
Datasource “db”: MySQL database
Error: Prisma schema validation - (get-config wasm)
Error code: P1012
error: Environment variable not found: DATABASE_URL.
→ schema.prisma:10
|
9 | provider = “mysql”
10 | url = env(“DATABASE_URL”)
|

Validation Error Count: 1
[Context: getConfig]

Prisma CLI Version : 4.12.0

do you mean i can’t add Prisma database ? unfortunate

It sounds like you could, you just couldn’t have it as a secret.