title: How to use Subscribers in TypeORM?
body: <p>Consider the following setup with <code>mongodb</code> ( the issue is presumably database agnostic ):</p>
  
  <p>entity/Person.ts</p>
  
  <pre><code>import { Entity, Column } from 'typeorm';
  
  @Entity
  export class Person {
    @Column()
    name: string;
  }
  
  </code></pre>
  
  <p>subscriber/PersonSubscriber.ts</p>
  
  <pre><code>import {
    EntitySubscriberInterface,
    EventSubscriber,
    InsertEvent,
  } from 'typeorm';
  import { Person } from '../entity/Person';
  
  @EventSubscriber()
  export class PersonSubscriber implements EntitySubscriberInterface&lt;Person&gt; {
    listenTo() {
      return Person;
    }
  
    afterInsert(event: InsertEvent&lt;Person&gt;) {
      console.log(event);
    }
  }
  
  
  </code></pre>
  
  <p>config/mongo.ts</p>
  
  <pre><code>import { MongoConnectionOptions } from 'typeorm/driver/mongodb/MongoConnectionOptions';
  
  export const mongoConfig: MongoConnectionOptions = {
    type: 'mongodb',
    host: 'localhost',
    database: process.env.DB_NAME,
    useNewUrlParser: true,
    useUnifiedTopology: true,
    synchronize: true,
    logging: false,
    entities: ['src/entity/**/*.ts'],
    migrations: ['src/migration/**/*.ts'],
    subscribers: ['src/subscriber/**/*.ts'],
    cli: {
      entitiesDir: 'src/entity',
      migrationsDir: 'src/migration',
      subscribersDir: 'src/subscriber',
    },
  };
  
  </code></pre>
  
  <p>index.ts</p>
  
  <pre><code>import { createConnection } from 'typeorm';
  import { mongoConfig } from 'config/mongo';
  
  createConnection(mongoConfig)
    .then(connection =&gt; {
      console.log('connection established');
    })
    .catch(console.error);
  
  </code></pre>
  
  <p><code>PersonSubscriber</code> is the first element of the <code>connection.subscribers</code> array, however after having inserted a Person document the <code>InsertEvent</code> is <strong>not</strong> logged to the console. </p>
  
  <p><strong>What's missing?</strong></p>
  
  <p>P.S. This is all the docs I've managed to gather</p>
  
  <ul>
  <li><p><a href="https://github.com/typeorm/typeorm/blob/master/docs/listeners-and-subscribers.md" rel="nofollow noreferrer">https://github.com/typeorm/typeorm/blob/master/docs/listeners-and-subscribers.md</a></p></li>
  <li><p><a href="http://typeorm.delightful.studio/classes/_connection_connection_.connection.html#subscribers" rel="nofollow noreferrer">http://typeorm.delightful.studio/classes/_connection_connection_.connection.html#subscribers</a></p></li>
  </ul>
  
  <p>All in all, they still don't tell the complete story.</p>