Installation

  1. Install the npm package:

    npm install typeorm --save

  2. You need to install reflect-metadata shim:

    npm install reflect-metadata --save

    and import it somewhere in the global place of your app (for example in app.ts):

    import "reflect-metadata";

  3. You may need to install node typings:

    npm install @types/node --save

  4. Install a database driver:

    • for MySQL or MariaDB

      npm install mysql --save (you can install mysql2 instead as well)

    • for PostgreSQL or CockroachDB

      npm install pg --save

    • for SQLite

      npm install sqlite3 --save

    • for Microsoft SQL Server

      npm install mssql --save

    • for sql.js

      npm install sql.js --save

    • for Oracle

      npm install oracledb --save

      Install only one of them, depending on which database you use.

      To make the Oracle driver work, you need to follow the installation instructions from their site.

    • for MongoDB (experimental)

      npm install mongodb --save

    • for NativeScript, react-native and Cordova

      Check documentation of supported platforms

TypeScript configuration

Also, make sure you are using TypeScript compiler version 3.3 or greater,and you have enabled the following settings in tsconfig.json:

  1. "emitDecoratorMetadata": true,
  2. "experimentalDecorators": true,

You may also need to enable es6 in the lib section of compiler options, or install es6-shim from @types.