Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tinchodias/pharo-dotenv
Pharo package that loads environment variables from a .env file into the process environment variables.
https://github.com/tinchodias/pharo-dotenv
pharo
Last synced: 27 days ago
JSON representation
Pharo package that loads environment variables from a .env file into the process environment variables.
- Host: GitHub
- URL: https://github.com/tinchodias/pharo-dotenv
- Owner: tinchodias
- License: mit
- Created: 2018-11-26T20:49:01.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-26T21:53:37.000Z (about 6 years ago)
- Last Synced: 2024-10-30T05:12:08.365Z (3 months ago)
- Topics: pharo
- Language: Smalltalk
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pharo-dotenv
Pharo package that loads environment variables from a .env file into the process environment variables.It is a basic port of the [nodejs dotenv module](https://github.com/motdotla/dotenv).
## Install
In Pharo 6.1 or 7.0, add this repository to Iceberg and load the only package. It has no Metacello baseline for the moment.
## Use
### Basic
If you have a `.env` file in the `FileSystem workingDirectory` with this content:
~~~
VAR1=var1
VAR2=var2
~~~Then, you can read values with:
~~~
Dotenv new variablesDictionary.
>>> "a Dictionary('VAR1'->'var1' 'VAR2'->'var2' )"
~~~### Apply to process environment variables
This is the scenario that the original dotenv project considers.
For example, if you run your web system in 2 different contexts:
* production: the environment variables USERNAME and PASSWORD define some credentials.
* development: the `.env` file defines both variables as in the Basic example shown above.You can equally access the variables this way:
~~~
Dotenv new config.credentials := Credentials
username: (OSPlatform current environment at: 'USERNAME')
password: (OSPlatform current environment at: 'PASSWORD').
~~~### Specify a custom path
This example works if you have the variables defined in `~/.credentials`:
~~~
Dotenv new
path: (FileLocator home / '.credentials') asFileReference;
config.
~~~### More
Browse `DotenvTest` class for more usage details.