Setup
Create a.env file in the root directory:
Database Configuration
boolean
default:"false"
Controls which database to use during development:
true- Use test database (DATABASE_URL_TEST)false- Use local or production database
boolean
default:"false"
Whether to connect to the production database:
true- Use production database (DATABASE_URL_PROD)false- Use local or test database
string
required
PostgreSQL connection string for local development database.Format:Example:
string
required
PostgreSQL connection string for test database used during automated testing.Format:Example:
string
required
PostgreSQL connection string for production database.Format (Neon):Example:
Authentication Configuration
string
required
Secret key used to sign JWT tokens and secure sessions. Must be a strong random string.Generation:Example:
string
required
The base URL where your application is accessible. Used for generating callback URLs and verification links.Development:Production:
Do not include a trailing slash.
SMTP Email Configuration
Concordia uses SMTP for sending transactional emails (verification, password reset, notifications).string
required
The name of your SMTP provider. Common values:
gmailsendgridmailguncustom
string
required
The email address or username for SMTP authentication.
string
required
The password or app-specific password for SMTP authentication.
string
required
The “From” email address used in outgoing emails.
Optional SMTP Configuration
string
Custom SMTP server hostname. If not set, automatically determined from
SMTP_PROVIDER.number
default:"587"
SMTP server port. Common values:
587- TLS (recommended)465- SSL25- Unencrypted (not recommended)
boolean
default:"false"
Whether to use SSL/TLS:
true- Use SSL (port 465)false- Use STARTTLS (port 587)
boolean
default:"true"
Whether to use connection pooling for better performance.
number
default:"5"
Maximum number of simultaneous SMTP connections in the pool.
number
default:"1000"
Time window in milliseconds for rate limiting.
number
default:"5"
Maximum number of emails to send within the rate limit window.
Alternative Email Provider: Resend
As an alternative to SMTP, you can use Resend for email delivery:string
API key from your Resend account. When set, Resend will be used instead of SMTP.
To use Resend, comment out or remove SMTP variables and set only
RESEND_API_KEY.Application Configuration
string
default:"development"
The environment mode for Node.js. Affects logging, error handling, and optimizations.Valid values:
development- Development mode with verbose loggingproduction- Production mode with optimizationstest- Test mode for automated testing
string
Public-facing API URL used by client-side code. Must be accessible from the browser.Development:Production:
Variables prefixed with
PUBLIC_ are exposed to client-side code. Never put secrets in PUBLIC_ variables.Complete Example Configuration
Here’s a complete.env file template with all variables:
.env
Testing Your Configuration
Test Database Connection
Test SMTP Configuration
Environment-Specific Files
- Development
- Production
- Testing
Create
.env.development:Security Best Practices
Never Commit Secrets
Never Commit Secrets
Add
.env* to your .gitignore:.gitignore
Generate Strong Secrets
Generate Strong Secrets
Use cryptographically secure random values:
Use Different Secrets Per Environment
Use Different Secrets Per Environment
Never reuse the same
BETTER_AUTH_SECRET across development, staging, and production.Rotate Secrets Regularly
Rotate Secrets Regularly
Change authentication secrets and API keys periodically, especially after:
- Team member departures
- Security incidents
- Suspected compromise
Limit Database Permissions
Limit Database Permissions
Use database users with minimal required permissions:
- Development: Full access to dev database only
- Production: No DDL permissions, only DML (SELECT, INSERT, UPDATE, DELETE)
Troubleshooting
Database Connection Failed
Database Connection Failed
Error:
Error: connect ECONNREFUSEDSolutions:- Ensure PostgreSQL is running:
- Check connection string format
- Verify username, password, and database name
- Test with
npm run db:check
SMTP Authentication Failed
SMTP Authentication Failed
Error:
Invalid login: 535-5.7.8 Username and Password not acceptedSolutions:- For Gmail: Use an App Password, not your account password
- Check
SMTP_USERandSMTP_PASSare correct - Verify SMTP provider settings
- Test with
npm run smtp:check
JWT Token Invalid
JWT Token Invalid
Error:
JsonWebTokenError: invalid signatureSolutions:- Ensure
BETTER_AUTH_SECRETis set and matches between environments - Check for whitespace or newlines in the secret
- Regenerate the secret if corrupted
Environment Variables Not Loading
Environment Variables Not Loading
Issue: Variables are undefined at runtimeSolutions:
- Ensure
.envfile is in the project root - Restart the development server after changing
.env - Check for typos in variable names
- Verify
dotenvis configured inastro.config.mjs
Next Steps
Database Setup
Learn about the database schema and migrations
Authentication
Configure authentication and user management