Overview
Environment variables are particularly useful for:Server Deployments
Configure MQTT Explorer for browser mode with predefined settings
Container Deployments
Deploy with Docker/Kubernetes using environment-based configuration
CI/CD Pipelines
Automated testing and deployment without manual configuration
Multi-Environment Setup
Easy switching between development, staging, and production environments
MQTT Connection Variables
Auto-Connect Configuration
Automatically connect to an MQTT broker when starting in server mode:The MQTT broker hostname or IP address to automatically connect to on startup.Required for auto-connect: Yes (triggers auto-connect when set)
When this variable is set, MQTT Explorer will automatically attempt to connect on startup without requiring user interaction.
The MQTT broker port to connect to.Common ports:
1883- Standard MQTT (non-encrypted)8883- MQTT over TLS/SSL8080- WebSocket8443- WebSocket over TLS
The connection protocol to use.Options:
mqtt- Standard MQTT protocolws- WebSocket protocol
Username for MQTT broker authentication.
Leave unset if your broker doesn’t require authentication.
Password for MQTT broker authentication.
Custom client ID for the MQTT connection.Default: Auto-generated as Use custom client IDs to:
mqtt-explorer- followed by random hex string- Identify connections in broker logs
- Enable persistent sessions
- Prevent conflicts between multiple instances
Auto-Connect Example
Server Authentication Variables
Configure authentication for the MQTT Explorer web interface (browser mode):Username for accessing the MQTT Explorer web interface.Default: If not set, generates random username like
user-a1b2c3d4Password for accessing the MQTT Explorer web interface.Default: If not set, generates random UUID password displayed in console on first startupSecurity features:
- Passwords hashed with bcrypt (10 rounds)
- Rate limiting: 5 attempts per IP per 15 minutes
- Timing-safe comparison to prevent timing attacks
Completely disable authentication for the web interface.When enabled, displays warning:
LLM Integration Variables
Configure AI Assistant features for intelligent topic suggestions:The LLM provider to use for AI Assistant features.Options:
openai- OpenAI GPT modelsgemini- Google Gemini models
API key for OpenAI (when using OpenAI provider).Get your API key from: https://platform.openai.com/api-keys
API key for Google Gemini (when using Gemini provider).Get your API key from: https://makersuite.google.com/app/apikey
Generic API key that works with either provider (fallback option).Priority order:
- Provider-specific key (
OPENAI_API_KEYorGEMINI_API_KEY) - Generic key (
LLM_API_KEY) - UI configuration (localStorage)
Maximum tokens to allocate for neighboring topics context in AI prompts.Default: 500 tokens (increased from 100 for better device detection)Impact:
- Higher values (1000): More context, better multi-device proposals, higher API costs
- Default (500): Good balance for most use cases
- Lower values (200): Less context, may miss device relationships, lower costs
The default was increased from 100 to 500 to better support multi-device automation proposals and complex topic hierarchies.
LLM Configuration Examples
HTTP Server Variables
Port for the MQTT Explorer web server to listen on.
Node.js environment mode.Options:Production mode changes:
development- Verbose logging, detailed errorsproduction- Minimal logging, generic error messages
- Credentials not logged to console
- Generic error messages (no stack traces)
- Enhanced security headers
- Stricter CORS policies
Comma-separated list of allowed CORS origins.
Enable HTTP Upgrade-Insecure-Requests header.When enabled, instructs browsers to upgrade HTTP requests to HTTPS automatically.
Enable X-Frame-Options header to prevent clickjacking.When enabled, sets
X-Frame-Options: DENY to prevent embedding in frames.Testing Variables
Used for automated testing and development:MQTT broker host for running automated tests.
MQTT broker port for running automated tests.
URL for browser mode testing (used by UI tests).
Use mobile viewport dimensions for UI testing.
Complete Deployment Examples
Production Server Deployment
Docker Compose
Kubernetes Deployment
Development Setup
Configuration Priority
When multiple configuration sources exist, priority is:- Environment variables (highest priority)
- Credentials file (
~/.mqtt-explorer-credentials.json) - UI configuration (localStorage in browser mode)
- Defaults (lowest priority)
Environment variables always override other configuration sources, making them ideal for deployment automation.
Security Best Practices
Never Commit Secrets
Add
.env, .env.*, and credentials files to .gitignore. Never commit API keys or passwords.Use Secrets Management
In production, use proper secrets management (Kubernetes secrets, AWS Secrets Manager, HashiCorp Vault).
Rotate Credentials
Rotate passwords and API keys regularly (every 90 days minimum).
Least Privilege
Use read-only MQTT credentials when possible. Grant minimum required permissions.
Enable Production Mode
Always set
NODE_ENV=production in production for security hardening.Restrict CORS
Set explicit
ALLOWED_ORIGINS in production. Never use wildcard in production.Troubleshooting
Environment variables not taking effect
Environment variables not taking effect
Causes:
- Variables not exported in shell
- Process started before variables were set
- Typo in variable name
Auto-connect not working
Auto-connect not working
Causes:
MQTT_AUTO_CONNECT_HOSTnot set- Connection parameters incorrect
- Broker not accessible
- Verify
MQTT_AUTO_CONNECT_HOSTis set:echo $MQTT_AUTO_CONNECT_HOST - Check broker connectivity:
telnet $MQTT_AUTO_CONNECT_HOST $MQTT_AUTO_CONNECT_PORT - Review server logs for connection errors
- Test credentials manually first
LLM features not available
LLM features not available
Causes:
- API key not set
- Invalid API key
- Wrong provider selected
- Check API key is set:
echo $OPENAI_API_KEY - Verify API key is valid (test with curl)
- Ensure
LLM_PROVIDERmatches your API key provider - Check server logs for API errors
CORS errors in browser mode
CORS errors in browser mode
Causes:
ALLOWED_ORIGINSdoesn’t include your domain- Wildcard disabled in production
Next Steps
Connection Setup
Learn about manual connection configuration in the UI.
Authentication
Understand authentication for both MQTT brokers and server access.
Docker Deployment
Deploy MQTT Explorer with Docker using environment variables.
Security Best Practices
Review complete security guidelines for production deployments.