.env file in the root directory to configure your bot.
Required Variables
DATABASE_URL
PostgreSQL connection string for the database.The connection string must include
sslmode=require or your PostgreSQL instance must be configured to accept SSL connections (as specified in src/db/index.ts:16-18).Optional Variables
PORT
Port number for the Express server (used for health checks and Spotify callback).3000
Usage: The main Express server listens on this port. If not specified, the application defaults to port 3000.
The bot also runs a Spotify callback server on port
8888 (hardcoded in src/index.ts:39). This is used exclusively for Spotify OAuth callbacks.SPOTIFY_CLIENT_ID
Spotify API client ID for music integration features.- Go to Spotify Developer Dashboard
- Create a new app
- Copy the Client ID
SPOTIFY_CLIENT_SECRET
Spotify API client secret for authentication.- From your Spotify app dashboard
- Click “Show Client Secret”
- Copy the secret
SPOTIFY_REDIRECT_URI
Callback URL for Spotify OAuth flow.http://127.0.0.1:8888/callback
Configuration:
- Add this URL to your Spotify app’s “Redirect URIs” in the dashboard
- If deploying remotely, update to match your server URL:
The redirect URI must exactly match one of the URIs configured in your Spotify app dashboard.
Environment File Setup
Create a.env file in the root directory of your project:
Environment Variable Loading
The application uses thedotenv package to load environment variables. This is configured in multiple locations:
Database Configuration (src/db/index.ts):
drizzle.config.ts):
Environment variables are loaded automatically when the application starts. No additional configuration is needed.
Validation
The application validates required environment variables on startup:DATABASE_URL is missing, the application will exit with an error message.
Production Considerations
Deployment Platforms
Different platforms have different ways to set environment variables: Railway:Troubleshooting
DATABASE_URL Not Found
Error:DATABASE_URL environment variable is not set
Solution:
- Ensure
.envfile exists in the root directory - Verify
DATABASE_URLis defined in.env - Check file permissions (must be readable)
- Restart the application after changes
SSL Connection Errors
Error:SSL connection required
Solution:
- Add
?sslmode=requireto your connection string - Or configure your PostgreSQL instance to accept SSL
- For local development, you may need to adjust
ssl: 'require'insrc/db/index.ts
Spotify Integration Not Working
Error: Spotify commands fail or return authentication errors Solution:- Verify all three Spotify variables are set:
SPOTIFY_CLIENT_ID,SPOTIFY_CLIENT_SECRET,SPOTIFY_REDIRECT_URI - Ensure redirect URI matches your Spotify app dashboard configuration
- Check that port 8888 is accessible
- Verify credentials are correct (no extra spaces or quotes)