You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rmannn edited this page May 20, 2021
·
5 revisions
Create a cli endpoint
Create a file at root next to your entry point named console.ts
Import your app module or any module you want to be loaded. Usually this is your main nestjs module.
// console.ts - example of entrypointimport{BootstrapConsole}from'nestjs-console';import{MyModule}from'./module';constbootstrap=newBootstrapConsole({module: MyModule,useDecorators: true});bootstrap.init().then(async(app)=>{try{awaitapp.init();awaitbootstrap.boot();awaitapp.close();}catch(e){console.error(e);awaitapp.close();process.exit(1);}});
Import the ConsoleModule in your main module
// module.ts - your moduleimport{Module}from'@nestjs/common';import{ConsoleModule}from'nestjs-console';import{MyService}from'./service';
@Module({imports: [ConsoleModule// import the ConsoleModule],providers: [MyService],exports: [MyService]})exportclassMyModule{}
You can now inject the ConsoleService inside any nestjs providers, controllers... You can also use the @Console and @Command decorators to register commands