Overview
The Inmobiliaria API uses environment variables for configuration. In development, these are loaded from a.env file using dotenv. In production, set these directly in your hosting environment.
In production environments,
dotenv is not loaded. Ensure all required variables are set in your deployment platform.Required Variables
These variables must be set for the application to function properly.Database Configuration
PostgreSQL connection string with credentials and database name.Format: SSL Support: Append
postgresql://user:password@host:port/databaseExample: postgresql://postgres:mypassword@localhost:5432/inmobiliariaIf the URL doesn’t include
search_path, the application automatically appends ?schema=public or &schema=public to ensure migrations target the correct schema.?sslmode=require for SSL connections (common in production).Authentication (Better Auth)
Secret key for signing and encrypting authentication tokens and cookies.Format: Long random string (minimum 32 characters recommended)Example:
Y2bzxRWDLe8q90dEwxfAWu8i1NNAgCI1Generate with: openssl rand -base64 32The base URL where the API server is running.Development:
http://localhost:10000Production: https://api.yourdomain.comThis URL is used for Better Auth callbacks and must match your actual API endpoint.
The URL of your frontend application.Development:
http://localhost:5173Production: https://yourdomain.comUsed for:- CORS configuration
- Email verification redirect URLs
- Password reset redirect URLs
- OAuth callback URLs
Email Configuration
API key from Resend for sending transactional emails.Format:
re_xxxxxxxxxxxxxxxxxxxxxxxxxxUsed for:- Email verification
- Password reset emails
- Contact form notifications
The sender email address for outgoing emails.Format: Must be a verified domain in ResendExample:
[email protected]Email address where contact form submissions are sent.Example:
[email protected]Purpose: Receives property valuation requests and contact inquiries from the website.Optional Variables
OAuth Providers
Google OAuth 2.0 client ID for Google Sign-In.Example:
123456789-abcdefghijklmnop.apps.googleusercontent.comSetup: Google Cloud ConsoleBoth
GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET must be set to enable Google authentication.Google OAuth 2.0 client secret.Example:
GOCSPX-xxxxxxxxxxxxxxxxxxxxxStorage Configuration
Storage backend for uploaded images.Options:
local- Store files on the server filesystems3- Store files in AWS S3 or S3-compatible storage (R2, B2, MinIO)
s3See Storage Configuration for detailed setup.Directory path for local file storage (only used when
STORAGE_DRIVER=local).Default: uploads (relative to project root)Example: /var/www/uploads or ./public/uploadsThe application automatically creates this directory if it doesn’t exist.
Base URL for accessing uploaded files.For local storage:
/uploads (default)For S3/CDN: https://cdn.yourdomain.comExamples:- Local:
/uploadsorhttps://yourdomain.com/uploads - S3:
https://mybucket.s3.us-east-1.amazonaws.com - CloudFront:
https://d111111abcdef8.cloudfront.net - Cloudflare R2:
https://pub-xxxxx.r2.dev
AWS S3 Configuration
Only required when
STORAGE_DRIVER=s3. Also compatible with S3-compatible services like Cloudflare R2, Backblaze B2, and MinIO.S3 bucket name for storing uploaded files.Example:
inmobiliaria-uploadsRequired when: STORAGE_DRIVER=s3AWS region where your S3 bucket is located.Example:
us-east-1, eu-west-1, auto (for Cloudflare R2)Required when: STORAGE_DRIVER=s3AWS access key ID with permissions to read/write/delete objects in the S3 bucket.Example:
AKIAIOSFODNN7EXAMPLERequired when: STORAGE_DRIVER=s3IAM Permissions needed:s3:PutObjects3:GetObjects3:DeleteObject
AWS secret access key corresponding to the access key ID.Example:
wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYRequired when: STORAGE_DRIVER=s3Custom S3 endpoint for S3-compatible services.When to use: Only needed for non-AWS S3 servicesExamples:
- Cloudflare R2:
https://[account-id].r2.cloudflarestorage.com - Backblaze B2:
https://s3.us-west-000.backblazeb2.com - MinIO:
https://minio.yourdomain.com
Leave empty/unset when using AWS S3. The SDK will use the standard AWS endpoint.
Upload Limits
Maximum file size for image uploads in megabytes.Default:
10 (10 MB)Example: 20 (for 20 MB limit)Applied to: Individual image filesMaximum number of files that can be uploaded in a single request.Default:
10Example: 15 (allow up to 15 images per property)Server Configuration
Port number for the API server.Default:
3000Example: 8080, 10000In many cloud platforms (Heroku, Render, etc.), this is set automatically by the platform.
Node.js environment mode.Options:
development- Enables detailed logging, loads.envfileproduction- Optimized for production, hides sensitive errors
- Cookie security settings (secure flag)
- Error message verbosity
.envfile loading (disabled in production)- Logging levels
Environment File Template
.env
Validation
The application validates critical environment variables on startup:Security Best Practices
Protect Secrets
Protect Secrets
- Never commit
.envfiles to version control - Add
.envto.gitignore - Use different secrets for development and production
- Rotate secrets periodically
Use Strong Secrets
Use Strong Secrets
- Generate
BETTER_AUTH_SECRETwith:openssl rand -base64 32 - Use unique, random values
- Minimum 32 characters recommended
Production Deployment
Production Deployment
- Set environment variables directly in your hosting platform
- Don’t rely on
.envfiles in production - Use secret management services (AWS Secrets Manager, etc.)
- Enable SSL/TLS for all connections
Database Security
Database Security
- Use strong database passwords
- Enable SSL connections (
?sslmode=require) - Restrict database access by IP when possible
- Use connection pooling with appropriate limits
Troubleshooting
Database Connection Failed
Database Connection Failed
Symptoms: Application crashes on startup with database connection errorSolutions:
- Verify
DATABASE_URLformat is correct - Check database server is running and accessible
- Verify credentials and database name
- For SSL connections, add
?sslmode=require - Check firewall rules and network connectivity
Email Sending Fails
Email Sending Fails
Symptoms: Email verification or password reset emails not deliveredSolutions:
- Verify
RESEND_API_KEYis valid - Ensure
EMAIL_FROMuses a verified domain in Resend - Check Resend dashboard for error logs
- Verify
BUSINESS_EMAILis set for contact forms
CORS Errors
CORS Errors
Symptoms: Frontend cannot connect to API, browser shows CORS errorsSolutions:
- Set
FRONTEND_URLto match your frontend domain exactly - Include protocol (
http://orhttps://) - No trailing slash in URL
- Check browser console for specific CORS error details
File Upload Errors
File Upload Errors
Symptoms: Images fail to uploadSolutions:
- For
local: EnsureUPLOAD_DIRhas write permissions - For
s3: Verify all S3 credentials are correct - Check IAM permissions for S3 bucket
- Verify
PUBLIC_UPLOAD_URL_BASEis accessible - Review upload size limits
See Also
- Database Configuration - PostgreSQL and Drizzle ORM setup
- Storage Configuration - File storage options and setup
- API Reference - API endpoint documentation