title: How to use Global module in NestJs
body: <p>I am using nest js for  back-end. For this project i started to use NestJs, and in the documentation i found that in nestJs we can build <code>Global Modules</code>. So my global module looks like this:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Module
  import {Global, Module} from "@nestjs/common";
  import {GlobalController} from "./global.controller";
  import {GlobalService} from "./global.service";
  @Global()
  @Module({
    imports:[],
    exports:[GlobalService],
    providers:[GlobalService],
    controllers:[GlobalController]
  })
  export class GlobalModule {}</code></pre>
  </div>
  </div>
  </p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Controller
  import { Controller, Get } from "@nestjs/common";
  import {GlobalService} from "./global.service";
  @Controller()
  
  export class GlobalController {
      constructor(private readonly getGlobalData: GlobalService) {
      }
      @Get('global')
      getGlobal(){
          return this.getGlobalData.getGlobalData()
      }
  }</code></pre>
  </div>
  </div>
  </p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//Service
  import { Injectable } from "@nestjs/common";
  @Injectable()
  export class GlobalService {
      private readonly global = [1,12,2]
      getGlobalData(){
       return this.global.map(d =&gt; d)
      }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>In my root module i registered my global module:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import { Module } from '@nestjs/common';
  import { AppController } from './app.controller';
  import { AppService } from './app.service';
  import {GlobalModule} from "./globalModule/global.module";
  
  @Module({
    imports: [GlobalModule], //register global module
    controllers: [AppController],
    providers: [AppService],
  })
  export class AppModule {}</code></pre>
  </div>
  </div>
  </p>
  <p>Now the module is working, and when i go to <code>..../global</code> i get my data from <code>global</code> array.
  How i understand we can create global module to avoid repeating the same code in each module.
  <br><strong>Question:</strong>  According to my example how can i use my global module in different modules?</p>