Koa Boilerplate π
Koa + Typescript + TypeORM codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
Features
- βοΈ Strict Typescript Configuration
- 𧬠TypeORM For ORM And Migration Configuration
- π Awilix-Koa For Dependancy Injection And Declarative Routing
- π Dockerized For Easy Deployments
- π― 100% Unit Test Coverage with Jest And Sinon
- π§ͺ Integration Test Configuration using Docker-Compose, Jest and SuperTest
- π CI/CD Pipelines With Travis
- π JWT Auth and Password Hashing
- π Environment Specific With Dotenv
- β Joi For Request Validation
- π Cleaner Code With ESLint And Prettier
- π§ Realworld Example Implementation
- π£ Ejection script to remove example code
Coming Soon
- π΅ Generator scripts to add controllers, middleware and services with tests
- π§ͺ More integration test coverage
Table of Contents
Prerequisites
- Node v12+
- Postgres v10+
- Docker
Local
-
Clone and Install
git clone <url> cd koa-boilerplate npm install npm run build -
Environment and DB setup
Add a .env file in the root of the directory with the following environment variables. Change connection URL as needed for your local postgres install
NODE_ENV=development PORT=3000 SECRET=foobar TYPEORM_CONNECTION=postgres TYPEORM_URL=postgres://postgres:Password1@localhost:5432/postgres TYPEORM_ENTITIES=build/src/entities/*.js TYPEORM_MIGRATIONS=build/migrations/*.js TYPEORM_MIGRATIONS_TABLE_NAME=migrations TYPEORM_MIGRATIONS_DIR=migrationsRun migrations using typeorm
npx typeorm migration:run -
Run locally
Start app locally to verify connection
npm run start:dev -
Test your local setup works
This should finish successfully to know you have a working local setup and any changes you have made are not breaking
npm run commitRuns:
- Build
- Linting
- Unit Tests
- Docker Build
- Integration Tests
Ejection
npm run eject
Removes the Realworld Example Code, Updates the Initial Migration while maintaining full code coverage
Commands
-
npm scripts
npm run <command>start:devRun typescript files directly using nodemon and tsnode. Detects changes and automatically restarts serverbuildRuns tsc to compile the app. Files are emitted to /build.ejectRemoves example codelintChecks for linting errors using ESLint configurationunittestRun jest unittests with code coverageunittest:watchDetects changes and automatically re-runs testsdocker:upStandup the dockerize app, a postgres docker image and a migration image that migrates the dbdocker:downTeardown the docker containersinttestRun integration tests against the docker imagesinttest:watchRun integration tests and watch for changescommitRuns the previouse commands to verify changes before commit. This command also runs in the pipeline
-
typeorm scripts
All TypeORM commands run on the configuration information specified in the .env folder. See TypeORM CLI Docs
npx typeorm <command>migration:runApply any reminaing migrations to the db specified inmigration:revertRevert the most recent migration appliedmigration:showShow all migrations with statusmigration:generate -n migrationNameHereCompare entities to current db schema and generate migration with changesmigration:create -n migrationNameHereCreate a new migration
Docs
Structure
- Coming Soon...
License
- MIT license
- Copyright 2020 Β© Evan Gordon Fleming.
