Skip to main content

repl

The REPL (called console) enables you to inspect the database through the lens of your application. Like other psy commands, console-oriented commands default to NODE_ENV=test; use NODE_ENV=development when you want to inspect your development database. The console package script is the supported entrypoint, not psy consolepsy is reserved for generators, migrations, sync, and db:reset.

# start local repl
NODE_ENV=development pnpm console
> u = await User.all()

Wait for the console to fully load before using auto-imported names — it does not live-reload, so exit and relaunch after code changes. Press ESC twice to exit.

Auto-imported models

By default, all of your models are loaded into the global namespace. However, to avoid class naming conflicts, all models will actually be namespaced based on their folder path, starting from the models directory. This means that if you have a model located at Nutrition/LogEntry, and another located at Weight/LogEntry, the class names in the repl will be NutritionLogEntry and WeightLogEntry, regardless of what their actual class names are.

Auto-imported services

Services are namespaced the same way, prefixed with Services and derived from the path relative to app/services/:

File PathConsole Name
app/services/NotificationService.tsServicesNotificationService
app/services/Host/OnboardingService.tsServicesHostOnboardingService

Adding custom globals

If you want to add additional globals to your repl, you can do so by modifying the conf/repl.ts file, adding any additional globals to the provided context. DreamCLI.loadRepl — imported from @rvoh/dream/system — is what wires up the auto-imported models and services above; add your own globals after calling it:

// conf/repl.ts
import './loadEnv.js'

import * as repl from 'node:repl'
import { DreamCLI } from '@rvoh/dream/system'
import initializePsychicApp from './system/initializePsychicApp.js'
import MyClass from '../services/MyClass'

const replServer = repl.start('> ')
export default (async function () {
await initializePsychicApp()
await DreamCLI.loadRepl(replServer.context)

// add your additional globals here:
replServer.context.MyClass = MyClass
})()

Dynamically importing files

For code that isn't auto-imported, use a dynamic import with a path relative to src/:

myHelper = (await import('./app/services/Host/pricingHelpers.js')).default