dotenv
Version, currently 0.5.05 versions
github.com/drum445/dotenv
Load .env files in crystal
27 stars
24 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
dotenv:
github: drum445/dotenv
version: ~> 0.5.0Then run:
shards installshard.yml
- Crystal
1.0.0- License
- MIT
- Author
- drum445
Dependencies
This version declares no dependencies.
README
dotenv
Loads a .env file in Crystal and optionally sets values directly into your ENV.
Will always return the .env file as a hash regardless of whether you chose to load into your ENV or not. Will treat a non-existent
.env file as an empty one.
Installation
- Add the dependency to your
shard.yml:
dependencies:
dotenv:
github: drum445/dotenv
- Run
shards install
Usage
require "dotenv"
Having a .env file
ENV=dev
PORT=3000
LOGGING=true
CORS=*
DB_DRIVER=mysql
DB_USERNAME=root
DB_PASSWORD=password
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=test
Using a file called .env and loading into your ENV
require "dotenv"
Dotenv.load # => {"ENV" => "dev", "PORT" => "3000", "LOGGING" => "true", "CORS" => "*", "DB_DRIVER" => "mysql", "DB_USERNAME" => "root", "DB_PASSWORD" => "password", "DB_HOST" => "localhost", "DB_PORT" => "3306", "DB_DATABASE" => "test"}
Using a file called .env and NOT loading into your ENV
require "dotenv"
hash = Dotenv.load(set_env: false)
Using a file NOT called .env and loading into your ENV
require "dotenv"
Dotenv.load(path: ".env.live")
Overriding
By default the existing environment will be overriden by contents of the .env file. To disable this behaviour pass false to override_env parameter:
require "dotenv"
hash = Dotenv.load(override_env: false)
Development
- Clone the repository:
git clone git@github.com:drum445/dotenv.git. There are no dependencies, so noshards installis needed (but won't do any harm). - Change into the project root directory:
cd dotenv. - Run specs:
crystal spec.
Contributing
- Fork it (https://github.com/drum445/dotenv/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- drum445 - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.5.0- Tagged
- Nov 17, 2022
- Commit
4c8829b85b2b- Crystal
1.0.0- Indexed
- yes
Dependents
- anthropic-cr
- buzz-bot
- golurker
- Jomashop Universal Deep Link Server
- CPot
- magiika
- cr-agent
- n2y
- bakenohana
- bcv-kemal
- snappy
- gmaps
and 12 more
Repository
github.com/drum445/dotenv
Metadata
- Created
- Aug 12, 2026
- Updated
- Sep 28, 2026
- Synced
- Sep 28, 2026
- Versions
- 5