Overview
Devark automatically manages environment variables for all modules. When you install a module, Devark:- Creates or updates your
.envfile - Injects required environment variables
- Preserves existing variables
- Uses atomic file operations to prevent data loss
Environment variables are stored in
.env files and are never committed to version control. Devark automatically adds .env to your .gitignore file.How Auto-Injection Works
Devark uses smart merging logic to handle environment variables:Merge new variables
New variables from the module are merged with existing ones. Existing variables are never overwritten.
Atomic write operation
Variables are written to a temporary file, synced to disk, then atomically renamed to
.env to prevent corruption.Implementation Details
Here’s how Devark’sinjectEnvVars function works:
src/utils/injectEnvVars.js
Why atomic writes?
Why atomic writes?
Atomic writes prevent data loss if the process is interrupted:
- Write to temporary file (
.env.tmp) - Sync to disk to ensure write completes
- Rename temp file to
.env(atomic operation on most filesystems)
.env file.Environment Variables by Module
Each Devark module requires specific environment variables:Google OAuth
.env
How to get credentials
How to get credentials
- Go to Google Cloud Console
- Create a new project or select existing
- Navigate to APIs & Services > Credentials
- Create OAuth 2.0 Client ID
- Set authorized redirect URI to your callback URL
- Copy Client ID and Client Secret
GitHub OAuth
.env
How to get credentials
How to get credentials
- Go to GitHub Settings > Developer settings
- Select OAuth Apps or GitHub Apps
- Click New OAuth App
- Set authorization callback URL
- Copy Client ID and generate Client Secret
Resend OTP
.env
How to get API key
How to get API key
- Sign up at Resend
- Navigate to API Keys in dashboard
- Create new API key
- Verify your sending domain
- Use verified domain in
FROM_EMAIL
MongoDB Template
.env
PostgreSQL Template
.env
Interactive Prompts
When installing a module, Devark prompts for credentials:Security Best Practices
Never Commit .env
Your
.env file contains sensitive credentials. Devark automatically adds it to .gitignore, but always verify:.gitignore
Use .env.example
Create a template file for your team:Commit this file to version control as documentation.
.env.example
Rotate Secrets Regularly
- Rotate API keys every 90 days
- Use different credentials for dev/staging/production
- Revoke compromised keys immediately
Use Environment-Specific Files
For different environments:Load the correct file based on
NODE_ENV.Working with Teams
Setup for New Team Members
Fill in credentials
Share development credentials securely (use password manager, not Slack/email):
.env
Sharing Credentials Securely
Advanced Usage
Loading Environment Variables
Devark-generated code automatically loads environment variables usingdotenv:
- JavaScript
- TypeScript
Multiple Environment Files
Load different configs based onNODE_ENV:
Validating Required Variables
Ensure all required variables are set:TypeScript Type Safety
Create a typed config object:config.ts
Troubleshooting
Environment variables not loading
Environment variables not loading
Check these common issues:
.envfile exists in project root (not in subdirectory)dotenv.config()is called before accessing variables- Variable names match exactly (case-sensitive)
- No quotes around values unless they contain spaces
- Restart your development server after changes
Variables overwritten after module install
Variables overwritten after module install
This shouldn’t happen - Devark preserves existing variables. If it does:
- Check if you have a backup:
.env.tmp - Variables with empty values (
"") might be skipped - File permissions might prevent proper read/write
injectEnvVars.js only sets values if they’re truthy.Sample values instead of real credentials
Sample values instead of real credentials
If you see placeholder values after installation:This means you left the prompts empty. Simply edit
.env and replace with real values:Source Code Reference
Devark’s environment variable management is implemented in:src/utils/injectEnvVars.js- Core injection logic with atomic writessrc/modules/*/install.js- Module-specific variable definitions (lines 193-199, 176-179)
Every module’s
install.js calls injectEnvVars(targetPath, envVars) after prompting for credentials and before completing installation.
