Skip to content

Unable to load .env in cwd  #93

Description

@RAPrograms

I'm unable to access my .env file which is placed in the cwd. Only in docker compose with the env_file set can I access my env vars.

My project layout

.
├── .env
├── app/
│   ├── src/
│   ├── build.rs
│   ├── Cargo.lock
│   ├── Cargo.toml
│   └── Dockerfile
└── docker-compose.yml

My code

#[macro_use] extern crate rocket;

mod lib { 
    pub mod templator;
}

mod signup;

use dotenv;

use std::env;

#[launch]
fn rocket() -> _ {
    dotenv::dotenv().ok();

    let my_var = env::var("Discord-Client-Id").expect("MY_VAR not found");

    println!("\n\nMY_VAR: {}\n\n", my_var);

    rocket::build()
        .mount("/", signup::get_routes())
}

Output

MY_VAR not found: NotPresent

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions