If you’ve ever worked with Rails, you’re likely familiar with the console, a tool that becomes second nature for exploring models, debugging, or modifying data quickly. Transitioning to NestJS, you might miss this handy feature, as it’s not available out of the box. However, you can create your own version.

A straightforward approach is to use Prisma, as its client is self-contained and easily integrated into a REPL. A simple script can get you started:

import { PrismaClient } from '@prisma/client';

async function main() {
  const prisma = new PrismaClient();
  const repl = require('repl').start('> ');
  repl.context.prisma = prisma;
}

main();

Place this script in a file like src/repl.ts and execute it:

npx ts-node src/repl.ts

Now, you can perform similar tasks as you would in a Rails console:

> await prisma.user.findMany()

While it doesn’t load the full Rails environment, it serves its purpose.

And yes, Prisma Studio exists

Before diving into building a custom REPL, consider that Prisma comes with Prisma Studio:

npx prisma studio

Prisma Studio provides a clean interface for viewing and editing tables. It’s excellent for browsing data but doesn’t quite capture the “let me try this query right now” feel of the Rails console. This is where the REPL comes in handy.

When the REPL is the Right Choice

  • Testing a query before integrating it into a service

In summary, a small REPL can be sufficient for quickly testing queries without the need to launch the entire application.