Skip to content
Velikiy Kirill edited this page Jun 12, 2024 · 3 revisions

Env Class

pub fn init() !Env;
pub fn get(env: *Env, key: []const u8) ![]const u8;
pub fn deinit(env: *Env);

The Env class in dotenv-zig is used for parsing and managing environment variables from a .env file.

Initialization

To use the Env class, you first need to initialize it with the path to the .env file:

var env: Env = try Env.init(&allocator, ".env");

Getting Environment Variables

You can then use the get method to retrieve environment variables:

const myVar = try env.get("MY_VAR");

Deinitialization

When you're done using the Env class, you should deinitialize it to free up resources:

env.deinit();

Clone this wiki locally