title: ConnectionNotFoundError: Connection "default" was not found
body: <p>Stack =&gt; Nodejs, Express.js, Typeorm</p>
  <p>I'm trying to use typeorm with typescript. I have created a repository to save the survivor information. But I keep getting this error:</p>
  <pre class="lang-sh prettyprint-override"><code>ConnectionNotFoundError: Connection &quot;default&quot; was not found.
      at new ConnectionNotFoundError (/Users/Wblech/codeminerTeste/backend/src/error/ConnectionNotFoundError.ts:8:9)
      at ConnectionManager.get (/Users/Wblech/codeminerTeste/backend/src/connection/ConnectionManager.ts:40:19)
      at Object.getRepository (/Users/Wblech/codeminerTeste/backend/src/index.ts:284:35)
      at new CreateSurvivorRepository (/Users/Wblech/codeminerTeste/backend/src/repositories/typeorm/CreateSurvivorRepository.ts:10:26)
      at Object.&lt;anonymous&gt; (/Users/Wblech/codeminerTeste/backend/src/useCases/CreateSurvivor/index.ts:6:41)
      at Module._compile (internal/modules/cjs/loader.js:774:30)
      at Module._compile (/Users/Wblech/codeminerTeste/backend/node_modules/source-map-support/source-map-support.js:547:25)
      at Module.m._compile (/private/var/folders/fr/6x3p83cj6r73h57k1_x6nctc0000gn/T/ts-node-dev-hook-7748782675459163.js:69:33)
      at Module._extensions..js (internal/modules/cjs/loader.js:785:10)
      at require.extensions..jsx.require.extensions..js (/private/var/folders/fr/6x3p83cj6r73h57k1_x6nctc0000gn/T/ts-node-dev-hook-7748782675459163.js:114:20)
  [ERROR] 00:28:59 ConnectionNotFoundError: Connection &quot;default&quot; was not found.
  </code></pre>
  <p>My ormconfig.json is this one:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;name&quot;: &quot;default&quot;,
    &quot;type&quot;: &quot;postgres&quot;,
    &quot;host&quot;: &quot;localhost&quot;,
    &quot;port&quot;: 5432,
    &quot;username&quot;: &quot;postgres&quot;,
    &quot;password&quot;: &quot;teste&quot;,
    &quot;database&quot;: &quot;codeminer_backend&quot;,
    &quot;entities&quot;: [
       &quot;src/database/models/*.ts&quot;
    ],
    &quot;migrations&quot;: [
       &quot;src/database/migrations/*.ts&quot;
    ],
    &quot;cli&quot;: {
      &quot;migrationsDir&quot;: &quot;./src/database/migrations&quot;
    }
  }
  </code></pre>
  <p>Those are the code that the error appoint:</p>
  <p><code>at new CreateSurvivorRepository (/Users/Wblech/codeminerTeste/backend/src/repositories/typeorm/CreateSurvivorRepository.ts:10:26)</code></p>
  <pre class="lang-js prettyprint-override"><code>import { getRepository, Repository } from 'typeorm'
  import { SurvivorOrm } from '../../database/models/SurvivorsOrm'
  import { ICreateSurvivorRequestDTO } from '../../useCases/CreateSurvivor/CreateSurvivorDTO'
  import { ICreateSurvivorRepository } from '../ICreateSurvivorRepository'
  
  export class CreateSurvivorRepository implements ICreateSurvivorRepository {
    private ormRepository: Repository&lt;SurvivorOrm&gt;
  
    constructor () {
      this.ormRepository = getRepository(SurvivorOrm)
    }
  
    public async create ({ id, name, age, gender, lastLocation, infected }: ICreateSurvivorRequestDTO): Promise&lt;SurvivorOrm&gt; {
      const survivor = await this.ormRepository.create({ id, name, age, gender, lastLocation, infected })
  
      await this.ormRepository.save(survivor)
  
      return survivor
    }
  }
  </code></pre>
  <p><code>at Object.&lt;anonymous&gt; (/Users/Wblech/codeminerTeste/backend/src/useCases/CreateSurvivor/index.ts:6:41)</code></p>
  <pre class="lang-js prettyprint-override"><code>import { CreateInventoryRepository } from '../../repositories/typeorm/CreateInventoryRepository'
  import { CreateSurvivorRepository } from '../../repositories/typeorm/CreateSurvivorRepository'
  import { CreateSurvivorController } from './CreateSurvivorController'
  import { CreateSurvivorUseCase } from './CreateSurvivorUseCase'
  
  const createSurvivorRepositoryTypeOrm = new CreateSurvivorRepository()
  const createInventoryRepositoryTypeOrm = new CreateInventoryRepository()
  
  const createSurvivorUseCase = new CreateSurvivorUseCase(
    createSurvivorRepositoryTypeOrm,
    createInventoryRepositoryTypeOrm
  )
  
  const createSurvivorController = new CreateSurvivorController(
    createSurvivorUseCase
  )
  
  export { createSurvivorUseCase, createSurvivorController }
  </code></pre>
  <p>My connection is in a file in the path './src/database/index.ts' and is this one:</p>
  <pre class="lang-js prettyprint-override"><code>import { createConnection } from 'typeorm'
  
  createConnection()
  </code></pre>
  <p>And I import the connection in this file called server.ts:</p>
  <pre class="lang-js prettyprint-override"><code>import express from 'express'
  import { router } from './router'
  import './database'
  
  const port = 8081
  
  const app = express()
  
  app.use(express.json())
  app.use(router)
  
  app.listen(port, () =&gt; console.log(`App running at ${port}`))
  </code></pre>
  <p>I'm really stuck at this</p>