Hey guys, I am mutating `process.env.DATABASE_URL`...
# orm-help
d
Hey guys, I am mutating
process.env.DATABASE_URL
before creating a Prisma client instance like
process.env.DATABASE_URL = ...
but unfortunately this results in
Copy code
error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:11
   | 
10 |   provider = "mysql"
11 |   url      = env("DATABASE_URL")
   |
Any idea what I can do?
m
I ran into the same problem earlier in my dev with Prisma. What helped was to make sure my
.env
file was being read properly.
Copy code
// in package.json
  "start": "ts-node-dev -r dotenv/config src/index.ts",

  "dependencies": {
     "dotenv": "^10.0.0", // Using dotenv
   }
Copy code
// in .env
DATABASE_URL="..."
d
I have a bit of a rare case where I fetch parameters from AWS Parameter Store because I'm doing Green/Blue deployment with GitHub actions + CodeDeploy EC2, I cannot use a .env file 😕
Copy code
/**
 * Load and set environment variables from AWS Parameter Store file, see: scripts/start_server.sh
 */
export function env() {
  const json: Record<"Parameters", Parameter[]> = JSON.parse(
    fs.readFileSync(".env.json", "utf8")
  )

  json.Parameters.forEach((p) => {
    const key = p.Name.split("/").pop()

    if (key) {
      process.env[key] = p.Value
    }
  })
}
Or well, maybe I can run something before starting the app
r
Could you try adding it to both of these and check?
Copy code
process.env.DATABASE_URL = `URL`
this.global.process.env.DATABASE_URL = `URL`