Skip to content

Environment

Environment variable management and .env file loading.

3 modules

ModuleDescription
Lấy biến môi trườngLấy giá trị của biến môi trường
Tải tệp .envTải biến môi trường từ tệp .env
Thiết lập biến môi trườngThiết lập biến môi trường trong tiến trình hiện tại

Modules

Lấy biến môi trường

env.get

Lấy giá trị của biến môi trường

Parameters:

NameTypeRequiredDefaultDescription
namestringYes-Tên của biến môi trường
defaultstringNo-Giá trị mặc định nếu biến chưa được thiết lập

Output:

FieldTypeDescription
namestringTên biến
valuestringGiá trị biến (hoặc mặc định nếu chưa thiết lập)
existsbooleanBiến có tồn tại trong môi trường không

Example: Get HOME variable

yaml
name: HOME

Example: Get variable with default

yaml
name: MY_APP_PORT
default: 8080

Tải tệp .env

env.load_dotenv

Tải biến môi trường từ tệp .env

Parameters:

NameTypeRequiredDefaultDescription
pathstringYes.envĐường dẫn đến tệp .env
overridebooleanNoFalseCó ghi đè biến môi trường hiện có không

Output:

FieldTypeDescription
loaded_countnumberSố lượng biến đã tải
variablesarrayDanh sách tên biến đã tải

Example: Load .env file

yaml
path: .env
override: false

Thiết lập biến môi trường

env.set

Thiết lập biến môi trường trong tiến trình hiện tại

Parameters:

NameTypeRequiredDefaultDescription
namestringYes-Tên của biến môi trường cần thiết lập
valuestringYes-Giá trị gán cho biến môi trường

Output:

FieldTypeDescription
namestringTên biến
valuestringGiá trị mới đã thiết lập
previous_valuestringGiá trị trước đó (null nếu chưa thiết lập trước)

Example: Set an environment variable

yaml
name: MY_APP_PORT
value: 3000

Released under the Apache 2.0 License.