/rust-env

Learn how to use file .ENV in your Rust projects. 🧪

Primary LanguageRustApache License 2.0Apache-2.0

¿How to use .env in Rust?

  1. First Add the dependency dotenv in your Cargo.toml
[dependencies]
dotenv="*"
  1. Load the .env file in your code
dotenv::from_path("./.env").expect("error loading env");
  1. Use the standard library for get your variables
let db_users = env::var("DB_USER").expect("env error");
let db_password = env::var("DB_PASSWORD").expect("env error");