VitNode

Modules

Organize your application into modules.

This guide is based of NestJS documentation.

After creating a new plugin, you can organize your work into modules. Modules are a way to group related components together. They can contain controllers, services, and other components.

Creating a module

To create a new module, create example.module.ts in the apps/backend/src/plugins/{your_plugin_code} directory. The module should be decorated with the @Module decorator. Name of the module should be unique, best practice is to use {feature}{plugin_code}Module as the name.

apps/backend/src/plugins/{your_plugin_code}/example/example.module.ts
@Module({
  imports: [],
  controllers: [],
  providers: [],
  exports: [],
})
export class ExampleWelcomeModule {}

The @Module() decorator takes an object with the following properties:

PropertyDescription
importsModules that are imported by this module.
controllersControllers that are part of this module.
providersServices that are part of this module.
exportsProviders that are exported by this module and can be used by other modules.

Importing a module

Make this module available. Go to the module root of your plugin. That's should be apps/backend/src/plugins/{your_plugin_code}/{your_plugin_code}.module.ts. Import the module and add it to the imports array.

apps/backend/src/plugins/{your_plugin_code}/{your_plugin_code}.module.ts
import { Module } from '@nestjs/common';
import { ExampleWelcomeModule } from './example/example.module'; 
 
@Module({
  imports: [ExampleWelcomeModule], 
})
export class WelcomeModule {}

Advanced usage

If you want to use global module, dynamic module please refer to the NestJS documentation.

On this page