Nest Logo

Stack

Nest framework TypeScript starter repository. Fastify Fastify TypeOrm TypeORM

Installation

$ yarn install

Running the app

# development
$ yarn start

# watch mode
$ yarn start:dev

# production mode
$ yarn start:prod

Test

# unit tests
$ yarn test

# e2e tests
$ yarn test:e2e

# test coverage
$ yarn test:cov

How to create this poc :

$ nest new poc-nest-api
# With yarn

$ yarn add fastify fastify-formbody
# change http provider for fastify
# https://docs.nestjs.com/techniques/performance

$ yarn add @nestjs/typeorm typeorm pg
# add typeorm and pg

need .env :

PORT=3001
DATABASE_URL=postgres://you_db_url
NEWRELIC_LICENCE_KEY=
ENTITIES_PATH=src/**/**.entity{.ts,.js}
MIGRATIONS_PATH=src/migrations/*{.js,.ts}
MIGRATIONS_DIR=src/migrations
REDISCLOUD_URL=

and ormconfig.json in root path :

{
  "type": "postgres",
  "url": "you_db_url",
  "entities": ["src/**/**.entity{.ts,.js}"],
  "migrations": ["src/migrations/*{.ts,.js}"],
  "cli": {
      "migrationsDir": "src/migrations"
  }
}

without this file the typeorm client doesn't work. install cli with : npm install -g ts-node

Npm script added to support typeorm on typescript file To generate a ts migration directly with entity change :

$ ts-node ./node_modules/typeorm/cli.js migration:generate -n CreateCategory
#Or with the npm script just type :
$ yarn typeorm migration:generate -n CreateCategory

To execute ts migration :

$ ts-node ./node_modules/typeorm/cli.js migration:run
#Or with the npm script just type :
$ yarn typeorm migration:run
#on heroku
$ heroku run typeorm migration:run -a poc-nest-api

deploy

Withou docker :

On heroku postinstall script is running https://devcenter.heroku.com/articles/nodejs-support#build-behavior

With docker :

heroku stack:set container -a poc-nest-api

seed