Git Product home page Git Product logo

koa-ts's Introduction

koa-ts

The best practice of building Koa2 with TypeScript. 中文


Usage

required NodeJS > 8.0

  1. Run npm init koa-ts.

  2. Install dependencies: yarn or npm i.

  3. Lift srever: yarn start or npm start. visit: http://127.0.0.1:3000/apis/sessions

  [Optional] if you need database, set useMongoDB to true.(in configs/customs.ts).

  [Optional] the project has built-in a docker-compose, run npm run mongo lift mongodb automatic.

Catalog

├── app
│   ├── controllers         ---  contoller
│   ├── helpers             ---  helper func (interceptor / error handler / validator...)
│   ├── jobs                ---  task (periodic task / trigger task / email server...)
│   ├── entities            ---  database entity (model)
│   └── services            ---  adhesive controller and model
├── config
│   ├── environments        ---  environment variable
│   ├── koa.middlewares     ---  middlewares for Koa
│   ├── routing.middlewares ---  middlewares for Routing Controller
│   ├── routing.options     ---  configs for Routing Controller
│   ├── connection          ---  database connection
│   ├── bootstrap           ---  lifecycle
│   ├── customs             ---  user settings
│   └── interceptors        ---  global interceptor
│   └── utils               ---  pure functions for help
└── test
    └── apis                ---  test cases
├── variables.env           ---  environment file

Feature

  • Separation configuration and business logic.

  • Export scheme model and interface, follow style of TypeScript.

  • Test cases and lint configuration.

  • The best practice for Dependency Injection in Koa project.

  • Deploy by ncc.

  • TypeScript hotload.


Lifecycle

  1. app.ts -> collect env vars environments -> coolect env files variables.env

  2. envs ready, call bootstrap.before()

  3. configs/connection.ts connecting external services (e.g. DB / Redis...)

  4. lift routing-controllers -> lift Koa middlewares -> register Container for DI

  5. start Koa。invoke bootstrap.after() after startup

  6. configs/connection.ts connected -> invoke bootstrap.connected()


About Environments

  • In development (NODE_ENV=development), read configurations from configs/environments/development.ts file, but it will still be overwritten by variables.env file.

  • In production (NODE_ENV=production), read configurations from configs/environments/production.ts file, but it will still be overwritten by variables.env file.


Reference


LICENSE

Licensed under the MIT LICENSE.

koa-ts's People

Contributors

wittbulter avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.