title: typescript express typeorm createconnection
body: <p>I am creating an app with typescript express node typeorm. I am having this issue where when I make a call through a service class to the database using typeorm, I get connection default was not found. Here are my code snippets:</p>
  
  <pre><code>//dataservice class
  import { Connection, getConnection, EntityManager, Repository, 
  getManager } from "typeorm";
  
  export class LeaveDataService {
  private _db: Repository&lt;Leave&gt;;
  
  constructor() {
      this._db = getManager().getRepository(Leave);
  }
  
  /**
   * applyForLeave
   */
  public applyForLeave(leave: Leave): void {
      if(leave !== null) {
          let entity: Leave  = this._db.create(leave);
          this._db.save(entity);
      }
  }
  
  /**
   * getAllLeaves
   */
  public async getAllLeaves(): Promise&lt;Array&lt;Leave&gt;&gt; {
      let leaves: Promise&lt;Array&lt;Leave&gt;&gt; = this._db.find({
          select: ["leaveDays","casualLeaveDays","id","staff","leaveType","endorsedBy","approvedBy"],
          relations: ["staff", "leaveType"],
          skip: 5,
          take: 15
      });
  
      return leaves;
  }
  </code></pre>
  
  <p>this is my ormconfig.json</p>
  
  <pre><code>{
      "type":"sqlite",
      "entities": ["./models/*.js"],
      "database": "./leaveappdb.sql"
  }
  </code></pre>
  
  <p>and this is the "controller" that responds to requests by calling the service class which is the first snippet:</p>
  
  <pre><code>import { Request, Response } from "express";
  import { LeaveDataService } from "../services/leaveDataService";
  import { LeaveIndexApiModel } from '../ApiModels/leaveIndexApiModel';
  
  
  
  const dataService: LeaveDataService = new LeaveDataService();
  
  export let index = async (req: Request, res: Response) =&gt; {
  let result = await dataService.getAllLeaves();
  let viewresult = new Array&lt;LeaveIndexApiModel&gt;();
  
  result.forEach(leave =&gt; {
      let apmodel = 
      new LeaveIndexApiModel(leave.leaveType.name, 
  `${leave.staff.firstname} ${leave.staff.lastname}`, leave.id);
      viewresult.push(apmodel);
  });
  
  
  return res.status(200).send(viewresult);
  }
  </code></pre>
  
  <p>then this is where I bootstrap my app.</p>
  
  <pre><code>import express = require('express');
  import bodyParser = require('body-parser');
  import path = require('path');
  import * as home from './controllers/home';
  import { createConnection } from 'typeorm';
  import * as leavectrl from "./controllers/leaveController";
  //create express server
  
  
  //create app db connection.
  createConnection().then(async connection =&gt; {
  const app = express();
  console.log("DB online!");
  const approot = './';
  const appport = process.env.Port || 8001;
  //setup express for json parsing even with urlencoding
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(express.static(path.join(approot,'dist')));
  
  //serve and respond to routes by api
  app.get('/home', home.home);
  app.get('/login',home.login);
  
  //routes for leave
  app.get('/api/leaves', leavectrl.index);
  //default fall through
  // app.get('*', (req: Request, res: Response)=&gt;{
  //     res.sendFile(approot,'dist/index.html');
  // });
  
  app.listen(appport, ()=&gt; console.log(`api is alive on port 
  ${appport}`));
  
  }).catch(error =&gt; console.log("Data Access Error : ", error));
  </code></pre>