A dotenv parser for Lune
lune-dotenv loads environtment variables from a .env
file and adds them into process.env
.
Warning
lune-dotenv is still in-development. Some features aren't implemented yet and there might be breaking changes to the API in the future.
git submodule add https://github.com/Eggflaw/lune-dotenv.git
Create a .env
file into the root directory of your project.
OPENCLOUD_KEY=OPENCLOUDKEYHERE
SECRETS="SECRETS"
You can now load the .env
file with lune-dotenv
local process = require("@lune/process")
local dotenv = require("Packages/lune-dotenv") -- Assuming you added lune-dotenv into Packages/
dotenv:load() -- Must come before accessing process.env
print(process.env.OPENCLOUD_KEY) -- Remove after you confirmed it's working
Loads a .env
file and add it into process.env
By default, load
will find a .env
file in the current working directory
If there is an environment variable with the same key name, lune-dotenv will not overwrite it.
Set overwrite
to true to avoid this.
dotenv:load(false)
print(process.env.HOME) -- "/home/yourname"
--============--
dotenv:load(true)
print(process.env.HOME) -- "NEWHOME"
You can give load
a custom path instead of finding a .env
in the current directory
dotenv:load(false, "tests/envs/path.env")
print(process.env.CUSTOM_PATH)
Parse .env
content and convert it into a table.
Use this if you don't want to load .env
into process.env
local content = fs.readFile(".env")
local env = dotenv:parse(content)
print(env)
- Basic values
- Multiline values
- Comments
- Variable Substitution
- Command Substitution
- Exports
References: