DEV Community 👩‍💻👨‍💻

prakash chokalingam
prakash chokalingam

Posted on

Codebytes: REPL it with NestJs

I am a big fan of byebug, a powerful ruby debugger, and I was thrilled to know about the REPL server in the NestJS V9 release notes.

debug infograph
source: manshagraphics-Flaticon

The REPL server acts as a debugger for NestJS by launching an interactive server with all of the context required for your nest app. So you can basically interact with all of your methods directly.

To start the REPL server in your NestJS app,

  • Make a REPL entry file called repl.ts alongside main.ts.

  • Include your app module to the repl method in the repl.ts file.

// repl.ts

import { repl } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  await repl(AppModule);
}
bootstrap();
Enter fullscreen mode Exit fullscreen mode
  • Launch your repl server using the below command,
npm run start -- --entryFile repl
Enter fullscreen mode Exit fullscreen mode

It will initiate an interactive node server, from which you can easily access your nest app methods by getting them,

get(AppService).sayHelloWorld()
Enter fullscreen mode Exit fullscreen mode

repl server exec screenshot

play with REPL on codesandbox

for more usage methods on REPL click here to read the official documentation.

Top comments (0)

Top Heroku Alternatives (For Free!)

Recently Heroku shut down free Heroku Dynos, free Heroku Postgres, and free Heroku Data for Redis on November 28th, 2022. So Meshv Patel put together some free alternatives in this classic DEV post.