matlab-dotenv

버전 1.0 (37.7 KB) 작성자: Pavel Roslovets
Load environment variables from .env file

다운로드 수: 7

업데이트 날짜: 2022/3/15

GitHub에서 호스트

GitHub에서 라이선스 보기

matlab-dotenv

Load environment variables from .env file

Description

Use .env files to store sensitive parameters like passwords, tokens, API keys etc. This tool allows you to automatically load all environment variables from .env file stored in current folder.

Installation

Approach 1 (easy and fast)

Execute in MATLAB:

eval(webread('https://raw.githubusercontent.com/roslovets/matlab-dotenv/main/installer/installweb.m'))

Approach 2 (manual)

Use Add-Ons Explorer in MATLAB to find and install matlab-dotenv.

Approach 3 (offline)

Download matlab-dotenv.mltbx from the latest release and open it in MATLAB.

Load environment variables

Use dotenv.load function to load environment variables from .env file.

Syntax

dotenv.load

dotenv.load(dotEnvFilePath)

Description

dotenv.load loads all environment variables from .env stored in current folder. Access loaded variables with getenv(___)

dotenv.load(dotEnvFilePath) allows you to specify absolute or relative path to the text file with env variables

Input arguments

  • dotEnvFilePath - absolute or relative path to the text file with env variables (.env). Scalar string | char array

Read environment variables

Use dotenv.read function to read environment variables from .env file to structure.

Syntax

env = dotenv.read

env = dotenv.read(dotEnvFilePath)

Description

env = dotenv.read reads all environment variables from .env stored in current folder into structure

env = dotenv.read(dotEnvFilePath) allows you to specify absolute or relative path to the text file with env variables

Input arguments

  • dotEnvFilePath - absolute or relative path to the text file with env variables (.env). Scalar string | char array

Output arguments

  • env - structure with values of variables. Scalar struct

Example

In current folder create file named .env file with content:

var1=text_value
mypass=securely_stored_password

Run this command in your script to load variables from created file:

dotenv.load

Access variables with built-in MATLAB function:

mypass = getenv("mypass")

If you use Git in your project add .env file to .gitignore.


Generated from GettingStarted.mlx with Live Script to Markdown Converter

인용 양식

Pavel Roslovets (2022). matlab-dotenv (https://github.com/roslovets/matlab-dotenv/releases/tag/v1.0), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2022a
R2016b 이상 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

code

code/+dotenv

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.