File Exchange

image thumbnail

env

version 1.0.0 (4.11 KB) by Florian Schwaiger
Reads values from environment variables or a config file in MATLAB.

4 Downloads

Updated 02 Jul 2019

GitHub view license on GitHub

In web development, there used to be several configuration files installed on each production server.
With the advent of cloud services, a persistent file system might not be available. Small micro-services
can be deployed and configured from pre-packed images (e.g. Docker) to scale up horizontally in short time.
These services usually come with some sort of base configuration, but credentials for related services
(e.g. a shared database) cannot be stored in the images. They must be provided at run-time through
environment variables.

So, in a production environment you usually want to configure your application through the environment,
but during devlopment it is quicker to share a default configuration through a file (e.g. `.env`).
This utility presents an easy way to read environment variables from three different sources.

This function allows to quickly access environment values and falls back to definitions in a local `.env` file.
This work is inspired by functionality common in web development.

It reads values from three sources in the following order:
1) System environment (getenv)
2) MATLAB preferences (getpref)
3) `.env` file on the path

Access to the `.env` file is cached, so subsequent calls do not impact performance as much.
The cache is invalidated whenever the `.env` file is modified on disk.

Cite As

Florian Schwaiger (2020). env (https://www.github.com/fschwaiger/matlab-env), GitHub. Retrieved .

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags