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 console.

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

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.

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, like so:

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

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

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

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

For non-interactive scripts, prefer a scratch TypeScript file that imports src/conf/global.js, initializes the app, runs the code, and exits. That gives you the same boot path as the console without relying on interactive stdout.