All Projects → unix → Koa Ts

unix / Koa Ts

Licence: mit
The best practice of building Koa2 with TypeScript

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Koa Ts

Koa Restful Boilerplate
Koa 2 RESTful API boilerplate
Stars: ✭ 146 (-33.64%)
Mutual labels:  koa2
Blog Service
blog service @nestjs
Stars: ✭ 188 (-14.55%)
Mutual labels:  koa2
Vue Mall Mobile
🔥 vue + koa + mongodb 搭建 mobile web 商城 (End。。。)
Stars: ✭ 201 (-8.64%)
Mutual labels:  koa2
Nobita
Nobita 是一个基于Koa而诞生的一款框架。
Stars: ✭ 152 (-30.91%)
Mutual labels:  koa2
Github Ranking
🔍GitHub不同语言热门项目排行,Vue.js做页面展示
Stars: ✭ 160 (-27.27%)
Mutual labels:  koa2
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (-14.55%)
Mutual labels:  koa2
Sactive Web
🚀 A dependency injection web framework for Node.js.
Stars: ✭ 143 (-35%)
Mutual labels:  koa2
Next Blog
基于react(ssr)服务端框架next.js和antd-design搭建的个人博客
Stars: ✭ 214 (-2.73%)
Mutual labels:  koa2
Sinn
a blog based on of react,webpack3,dva,redux,material-ui,fetch,generator,markdown,nodejs,koa2,mongoose,docker,shell,and async/await 基于react+koa2技术栈的个人开源博客系统
Stars: ✭ 175 (-20.45%)
Mutual labels:  koa2
Koa Web Kit
🚀A Modern, Production-Ready, and Full-Stack Node Web Framework with React
Stars: ✭ 199 (-9.55%)
Mutual labels:  koa2
Koa Session2
Middleware for Koa2 to get/set session
Stars: ✭ 156 (-29.09%)
Mutual labels:  koa2
Async Busboy
Promise based multipart form parser for KoaJS
Stars: ✭ 159 (-27.73%)
Mutual labels:  koa2
Video Admin
node+koa2+mysql
Stars: ✭ 192 (-12.73%)
Mutual labels:  koa2
Vue Webpack Config
Koa2、Webpack、Vue、React、Node
Stars: ✭ 151 (-31.36%)
Mutual labels:  koa2
React Ssr
React 服务端渲染(SSR),react + redux + koa2 + sequelize + mysql全栈项目(Full Stack)
Stars: ✭ 205 (-6.82%)
Mutual labels:  koa2
Yn
Yank Note 一款面向程序员的 Markdown 笔记应用。支持加密文档,代码片段运行,内置终端,图表嵌入,HTML 小工具。
Stars: ✭ 143 (-35%)
Mutual labels:  koa2
Wind Layer
🎏 🚀 wind-layer | a openlayers && amap && bmap && leaflet && mapbox-gl extension to windjs
Stars: ✭ 188 (-14.55%)
Mutual labels:  koa2
Koa Webpack Middleware
webpack dev&hot middleware for koa2
Stars: ✭ 215 (-2.27%)
Mutual labels:  koa2
Bilibili Vue
前端vue+后端koa,全栈式开发bilibili首页
Stars: ✭ 2,590 (+1077.27%)
Mutual labels:  koa2
Egg Core
A core Pluggable framework based on koa.
Stars: ✭ 194 (-11.82%)
Mutual labels:  koa2

koa-ts

The best practice of building Koa2 with TypeScript. 中文


Usage

This layout requires NodeJS v12+

  1. Run npm init koa-ts.

  2. Install dependencies: yarn or npm i.

  3. Start the server: yarn dev or npm dev. visit: http://127.0.0.1:3000/apis/sessions

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

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


Project Layout

├── app
│   ├── controllers         ---  server controllers
│   ├── helpers             ---  helper func (interceptor / error handler / validator...)
│   ├── jobs                ---  task (periodic task / trigger task / email server...)
│   ├── entities            ---  database entities/models
│   └── 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                    ---  utils for testcase
├── 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 -> collect 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()


Databases

You can link multiple databases (mysql / mongo etc.), each database can link configurations of multiple environments:

  1. You can specify link configs of multiple environments under folder configs/environments.
  2. You can specify encrypted information in file variables.env. It is not recommended to add file variables.env to version control.
  3. You can still manually set process.env to override all environment variables.

About Environments

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

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


Reference


LICENSE

This project is licensed under the MIT License. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].