Skip to content

kryz81/koa-ts-boilerplate

Repository files navigation

Node.js App Boilerplate

Build Status Coverage Status Known Vulnerabilities Maintainability

Features

  • Language: Typescript
  • Framework: Koa
  • API Docs: Swagger + Koa Docs Generator
    • Swagger
    • Koa Swagger Decorator
  • Testing
    • Unit tests: Jest
    • Functional tests: Supertest, MongoDB In-Memory
  • Linting
    • Eslint with Typescript
  • Code Formatting
    • Prettier
    • Editorconfig
  • Database
    • Mongoose
    • Typegoose
  • Requests validation: class-validator
  • Background jobs: Agenda
  • Event Manager
  • Logging with winston
  • Dependency Injection
  • Commits linting: Commitlint + Husky
  • Docker
    • Development environment
    • Production environment
  • Database migrations (migrate-mongo)
  • Continuous Integration
    • Travis CI
    • Coveralls
  • Code quality check
    • Code Climate
  • Security Check
    • Snyk

To fix

  • Configure Node.js global object and remove "(global as any)"
  • Output "id" instead of "_id" (virtual property with typegoose?)
  • yarn runs either all dependencies or only production deps, how to install dev dependencies ONLY?
  • Command "docker-compose exec web yarn test:once" fails -> no tests to run found

Install and start developing (locally, without docker)

  • create .env, copy content from .env.dist and set variables, for example: APP_PORT=3000, DB_HOST=localhost:27017, DB_NAME=myapp
  • .env file is ignored by git and shouldn't be pushed to repo
  • yarn (or: npm i)
  • run in development mode: yarn start:dev (or: npm run start:dev)
  • run tests in development mode: yarn test (or: npm test)
  • seed database with example data: yarn migrate:dev (or: npm run migrate:dev)

Develop using docker machine

Command Description
docker-compose up start in development mode (no debugger enabled)
MODE=debugging docker-compose up start in development mode with debugger attached

Commands

Command Description
start:prod run production version (must be built with "build" command
start:dev run in development mode
start:development the same as start:dev
start:debugging run in development mode with enabled debugger
build build production version
clean remove node_modules, coverage, built app and so on
test run tests in watch mode
test:once run all tests once
test:coverage run all tests and export code coverage
lint lint code
format:check check code for formatting issues
format:write check and automatically fix formatting issues

Build and run in production

  • yarn build && yarn start:prod (or: npm run build && npm run start:prod)

Swagger UI

Open: localhost:3000/api-docs/html or localhost:3000/api-docs/json

How to debug with docker and intelliJ

  • Edit configurations -> new configuration -> Attach to Node.js/Chrome
  • Host: localhost, port: 9229
  • Run docker machine with debugger: MODE=debugging docker-compose up
  • Run "debug"

About

Backend App with Koa and Typescript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •