alepha@docs:~/docs/reference/primitives$
cat $mode.md1 min read
#$mode
#Import
typescript
1import { $mode } from "alepha";
#Overview
Environment variable to check for.
- The mode activates when:
- The env variable is truthy (e.g.
MIGRATE=true), OR
- The env variable is truthy (e.g.
- The
MODEenv equals this value (e.g.MODE=MIGRATE)
- The
- @example "MIGRATE"
- @example "SEED"
- @example "CONSOLE" */ env: string;
/**
- Callback to execute when the mode is activated and the app is ready.
- After the callback completes (or throws),
alepha.stop()is called automatically - to ensure graceful shutdown (close DB connections, etc.).
- If omitted, the mode activates (graph is pruned) but the process stays alive.
- Useful for long-running modes like queue workers or cron.
*/
ready?: (alepha: Alepha) => void | Promise
; }
// ---------------------------------------------------------------------------------------------------------------------
/** Activate a selective bootstrap mode.
When the environment condition matches, the owning class becomes alepha.target:
the DI graph is pruned to only this class and its transitive dependencies.
Everything else (HTTP server, job scheduler, etc.) is discarded.
Returns true if the mode is active, false otherwise.
#Examples
ts
1import { $mode, $inject } from "alepha"; 2import { DatabaseProvider } from "alepha/orm"; 3 4class DbMigrationMode { 5 db = $inject(DatabaseProvider); 6 7 mode = $mode({ 8 env: "MIGRATE", 9 ready: async () => {10 await this.db.migrate();11 },12 });13}
bash
MIGRATE=true node app.js # runs migrations, then exits
MODE=MIGRATE node app.js # same effect