npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa2-base

v3.0.10

Published

一个完整的 koa2 typescript 开发框架

Downloads

83

Readme

koa2-base typescript+koa2框架 3.1

一个完整的 koa2 typescript 开发框架

环境要求

nodejs > 7.6 开发工具:vscode 最佳

使用方式

git clone https://github.com/githbq/hbq-koa2-base.git

初始化操作

yarn
// or 
npm i 

启动方式

# 直接由ts-node引导入口文件无需编译,代码变更时由 `nodemon` 重新启动服务
npm start 

开发

路由定义

路由目录: src/routers/

  • help 以外目录都会自动识别路由
  • src/routers/demo/test.ts
    • 对应路径 http://localhost:6001/demo/test/[route-name]
  • 你可以添加自定义文件或者文件夹,会自动以目录层级作为路由路径进行注册

业务逻辑定义

业务逻辑目录: src/controllers/

  • 该目录支持多层级,与路由目录一一对应
  • 架构会自动将该 src/controllers/demo/test.ts 导出的对象,注入到与之相对应的 src/routers/demo/test.ts 导出的函数参数中:
// src/controllers/demo/test.ts
export default ({ debug, logger }) => {
    return {
         async hello(){
             return 'hello world'
         }
    }
}
// src/routers/demo/test.ts
export default (router, { controller }) => {
    router.get('/hi', async (ctx, next) => {
        ctx.body = controller.hello()
        // 访问: http://localhost:6001/demo/test/hi 
        // 响应: 'hello world'
    })
}

支持pm2部署: 用于生产环境

 npm run pm2

实时监听并且在浏览器上打开对应端口的地址

npm run pstart

注意事项

  1. npm start 执行的是 ts-node 引导 src/index.ts 不需要再监听ts文件实时编译
  2. 默认不主动链接 mongodb ,对应配置如下
    • /src/common/configs/appConfig.ts
      • useMongodb: false,
      • mongodb: 'mongodb://127.0.0.1:17951/koa2Base',

环境变量

  • NODE_ENV 环境变量有两个值
    • development 用于标识当前是开发环境
    • test 用于标识当前是测试环境
    • production 用于标识当前是生产环境(正式上线环境)
  • CONFIG_MODE 用于选择启用配置文件
    • /src/common/configs/appConfig-${CONFIG_MODE}.ts

如何调试

  • 推荐使用 vscode 开发工具

在vscode下调试

  1. 快捷键 ctrl + ,
  2. 搜索 自动附加 或者 autoAttach 设置为true
  3. npm run debug

目录结构

├── README.md
├── __tests__
|  ├── index.test.ts
|  └── readme.md
├── build
|  ├── app.js
|  ├── app.js.map
|  ├── common
|  ├── controllers
|  ├── index.js
|  ├── index.js.map
|  ├── routers
|  └── server
├── jest.config.js
├── package.json
├── public
|  ├── common
|  ├── favicon.ico
|  ├── index.html
|  ├── libs
|  └── pages
├── run.js
├── src
|  ├── app.ts
|  ├── common
|  ├── controllers
|  ├── globals.d.ts
|  ├── index.ts
|  ├── routers
|  ├── server
|  └── shims.d.ts
├── temp
|  └── logs
├── temp.upload
|  └── 1
├── tsconfig.json
├── tslint.json
├── upload
├── views
|  ├── ejs
|  └── pug
└── yarn.lock