@hairy/lnv v6.4.0
@hairy/lnv
Loading environment variables in Next.js and other frameworks can be quite cumbersome, and using dotenv or vault at runtime is also inconvenient. That's why my created this tool
I think it can solve some of the problems you encounter in next.js or dotenv or more. 🛠️
✅ Features
- 🔄 Multi-mode support, allowing you to load
.env|.env.prod|.env.localsimultaneously - 🔐 Support for vault.dotenv remote environment variable loading and multi-environment switching
- 🛡️ Direct writing to process.env, no local storage, more secure and reliable
- 📁 Environment variables lookup, naturally supports monorepo architecture
- 🏃♂️ Run any JS and scripts with environment variables
📦 Install
npm install @hairy/lnv
# or globally
npm install -g @hairy/lnv🚀 Usage
Modify the scripts field in your package.json:
{
"scripts": {
"dev": "lnv staging -- next dev"
}
}This will launch next dev with the .env.staging environment variables. ✨
You can also include any run parameters, for example:
lnv prod -- next dev --turbopack🌿 Default Environment Variables
You can include default environment variables using the --default|-d parameter:
# Will include .env.local and .env environment variables
lnv -d -- node index.js
# Equivalent to
lnv local env -- node index.js🔒 Vault Environment Variables
Before loading variables from vault, you need to connect to the vault environment variable repository in your project:
# Create and connect to vault repository
npx dotenv-vault@latest new
# Connect to an existing vault repository
npx dotenv-vault@latest vlt_...
# And encrypt your environment variables:
npx dotenv-vault@latest pull
# or
npx dotenv-vault@latest buildNext, you need to create a .env.key or .env.keys file in your project root directory and write the DOTENV_KEY:
# .env.key
DOTENV_KEY = dotenv://...?environment=development
# or
# .env.keys
DOTENV_KEY_DEVELOPMENT = dotenv://...?environment=development
DOTENV_KEY_CI = dotenv://:...?environment=ci
DOTENV_KEY_STAGING = dotenv://:...?environment=staging
DOTENV_KEY_PRODUCTION = dotenv://:...?environment=productionFinally, you can use the lnv command to include vault environment variables:
# Load environment variables based on .env.vault and .env.key
lnv --vlt -- node index.js
# Load ci environment variables based on .env.vault and .env.keys
lnv --vlt ci -- node index.js🚢 Vercel with Vault
If you need to deploy on Vercel, you need to add environment variables in your Vercel project:
npx vercel@latest env add DOTENV_KEYlnv vault will automatically load environment variables based on .env.vault. 🎉
✍️ Manual with environment variables
You can manual load environment variables with the -v|--value parameter:
lnv -v KEY1=VALUE1 -v KEY2=VALUE2 -- node index.js🔍️ Options
lnv <entry> [args]
args:
--version show version [boolean]
-v, --value set environment variables [array]
-e, --entry Explicit loading of entry, same as lnv <entry> [string]
--vault, --vlt load environment variables from vault [string]
-c, --cmd load runtime environment and run any scripts [string]
--expose expose environment variables [boolean]
-d, --default the default environment (env|env.local) be loaded [boolean]
-o, --overflow deep find and merge environment variables [boolean]
-h, --help show help [boolean]📄 License
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
12 months ago
12 months ago
11 months ago
11 months ago
9 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
12 months ago
12 months ago
2 years ago
2 years ago
2 years ago