A Fully Customized and Production Grade Koa REST API Implementing GoThinksters' RealWorld
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=migrations
Run 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 commit
Runs:
npm run eject
Removes the Realworld Example Code, Updates the Initial Migration while maintaining full code coverage
npm scripts
npm run <command>
start:dev
Run typescript files directly using nodemon and tsnode. Detects changes and automatically restarts serverbuild
Runs tsc to compile the app. Files are emitted to /build.eject
Removes example codelint
Checks for linting errors using ESLint configurationunittest
Run jest unittests with code coverageunittest:watch
Detects changes and automatically re-runs testsdocker:up
Standup the dockerize app, a postgres docker image and a migration image that migrates the dbdocker:down
Teardown the docker containersinttest
Run integration tests against the docker imagesinttest:watch
Run integration tests and watch for changescommit
Runs the previouse commands to verify changes before commit. This command also runs in the pipelinetypeorm scripts
All TypeORM commands run on the configuration information specified in the .env folder. See TypeORM CLI Docs
npx typeorm <command>
migration:run
Apply any reminaing migrations to the db specified inmigration:revert
Revert the most recent migration appliedmigration:show
Show all migrations with statusmigration:generate -n migrationNameHere
Compare entities to current db schema and generate migration with changesmigration:create -n migrationNameHere
Create a new migration