Mode
Profiles for your Robo session with distinct configurations, environment variables, and code.
Modes define profiles for your Robo.js session. Each mode can have its own configuration files, environment variables, and code paths. You can also run multiple modes simultaneously.
Running a Mode
Use the --mode flag to activate a custom mode:
robo dev --mode <mode>This makes Robo.js prioritize mode-specific files like .env.<mode> and robo.<mode>.js over the defaults.
Note: A mode can be any lowercase string without spaces or commas. For example: beta, staging, strict.
Use Cases
A/B Testing
Test different configurations by running separate modes:
robo dev --mode expensiveA .env.expensive file could contain values like ECONOMY_MULTIPLIER="2" or ECONOMY_TAX="0.1".
AI Personalities
Run multiple chatbot personalities simultaneously:
robo dev --mode catgirl tsundere weirdoEach mode uses a different .env.<mode> file with its own bot token and a custom ai.<mode>.mjs config file.
Beta Testing
Isolate beta features with a dedicated mode:
robo dev --mode betaA .env.beta file can point to different tokens or feature flags.
Experimental Features
Run experimental code in a separate mode:
robo dev --mode gpt4A .env.gpt4 file provides different tokens or API keys. A smart.gpt4 module folder can contain commands specific to this mode.
Secure Tokens
Enable additional security features only in production using mode-specific modules:
robo startA security.production module folder can contain middleware for rate limiting or other production-only security features.
Staging Environments
Use a staging mode to test against different databases or services before deploying:
robo start --mode stagingA .env.staging file points to staging databases and services.
File Conventions
The following Robo.js features support modes:
- Environment variable files (
.env.<mode>) - Robo config files (
robo.<mode>.js) - Plugin config files (
pluginname.<mode>.js) - Module folders (
module.<mode>)
When a mode is active, Robo.js prioritizes mode-specific files over defaults:
| Mode-based | Default |
|---|---|
.env.<mode> | .env |
robo.<mode>.js | robo.js |
ai.<mode>.mjs | ai.mjs |
security.<mode> | security |
If a mode-specific file does not exist, the default file is used.
Mode-Specific Modules
Create modules that only load when a specific mode is active by adding a .<mode> suffix to the module folder name:
The rate-limiting.ts middleware loads only when the production mode is active. During robo dev, it is skipped entirely.
This pattern also works for slash commands and other features, allowing entire feature sets to be gated behind a mode.
Default Modes
A mode is always active. The dev command uses development mode, and the start command uses production mode. If a NODE_ENV environment variable is set, that value is used instead.
# Mode: development
robo dev# Mode: production
robo start# Mode: beta
NODE_ENV=beta robo devSince a mode is always set, you can use files like .env.development for development-specific values by default.
Multiple Modes
Run multiple modes simultaneously by listing them after the --mode flag:
robo dev --mode <mode1> <mode2> <mode3>Each mode runs in a separate process. Logs are prefixed with the mode name for identification.
Note: Each mode runs as a separate process, so multiple modes use additional system resources.
JavaScript API
The Mode object provides runtime access to the current mode:
import { logger, Mode } from 'robo.js'
export default () => {
if (Mode.is('development')) {
logger.info('This mode is being', Mode.color('tested'))
}
return `Running in ${Mode.get()} mode!`
}import { logger, Mode } from 'robo.js'
export default () => {
if (Mode.is('development')) {
logger.info('This mode is being', Mode.color('tested'))
}
return `Running in ${Mode.get()} mode!`
}| Method | Description |
|---|---|
color(text) | Returns a string colored with the current mode's color. |
get() | Returns the current mode. |
is(mode) | Returns true if the current mode matches. |
isDev() | Returns true if running via robo dev, regardless of the --mode setting. |
Note: Modes cannot be changed at runtime. Use the --mode flag from the command line instead.
