Dotenv can't find my .env

I'm trying to load env variables from my .env file with dotenv

pub async fn server() -> Result<(), impl Error> {
//some code
    println!("{}", dotenv().unwrap().display());
//some code

The .env file is in my root dir and I already moved it to my src dir.

called `Result::unwrap()` on an `Err` value: Io(Custom { kind: NotFound, error: "path not found" })

Im trying to load the env variable like this.

let database_url: String = std::env::var("DATABASE_CON").expect("DATABASE_CON must be set.");

.env is opened at runtime. It should be in your working directory: the directory from where you launch your binary.

Or it parent folder according to the documentation, but I'm not sure on this one.

1 Like

I had to move the .env in my Docker container.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.