# reus.js

> cli for webapp development & deployment by nodejs

Latest version **6.0.0** (published 2026-07-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install reus.js
pnpm add reus.js
yarn add reus.js
bun add reus.js
```

Provides the command `reus`.

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2026-07-22 |
| First published | 2019-06-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^22.22.0 \|\| ^24.0.0 \|\| >=26.0.0 |
| Dependencies | 24 |
| Unpacked size | 241.5 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | guoz5658 |
| Maintainers | guozhi5658 |
| Keywords | cli, koa framework, webapp |

## Links

- npm: https://www.npmjs.com/package/reus.js
- Repository: https://github.com/scofield5658/reus
- Homepage: https://github.com/scofield5658/reus#readme
- Issues: https://github.com/scofield5658/reus/issues
- npm.io page: https://npm.io/package/reus.js

## Dependencies (24)

- [qs](https://npm.io/package/qs.md) 6.15.2
- [koa](https://npm.io/package/koa.md) 3.2.1
- [gulp](https://npm.io/package/gulp.md) 5.0.1
- [colors](https://npm.io/package/colors.md) 1.4.0
- [yamljs](https://npm.io/package/yamljs.md) 0.3.0
- [nodemon](https://npm.io/package/nodemon.md) 3.1.14
- [koa-body](https://npm.io/package/koa-body.md) 8.0.0
- [unzipper](https://npm.io/package/unzipper.md) 0.12.5
- [commander](https://npm.io/package/commander.md) 2.20.3
- [fancy-log](https://npm.io/package/fancy-log.md) 1.3.3
- [koa-mount](https://npm.io/package/koa-mount.md) 4.2.0
- [@types/koa](https://npm.io/package/@types/koa.md) 3.0.3
- [gulp-babel](https://npm.io/package/gulp-babel.md) ^8.0.0
- [gulp-clean](https://npm.io/package/gulp-clean.md) 0.4.0
- [koa-static](https://npm.io/package/koa-static.md) 5.0.0
- [@babel/core](https://npm.io/package/@babel/core.md) 7.29.7
- [@koa/router](https://npm.io/package/@koa/router.md) 15.7.0
- [koa-compose](https://npm.io/package/koa-compose.md) 4.1.0
- [koa-connect](https://npm.io/package/koa-connect.md) 2.1.1
- [browser-sync](https://npm.io/package/browser-sync.md) 3.0.4
- [koa2-swagger-ui](https://npm.io/package/koa2-swagger-ui.md) 5.12.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) 7.29.7
- [http-proxy-middleware](https://npm.io/package/http-proxy-middleware.md) 4.2.0
- [rate-limiter-flexible](https://npm.io/package/rate-limiter-flexible.md) 1.3.2

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 6.0.0 (latest) — 2026-07-22
- 5.1.0 — 2026-07-17
- 5.0.9 — 2026-07-16
- 5.0.8 — 2026-07-16
- 5.0.7 — 2026-02-06
- 5.0.6 — 2026-02-06
- 5.0.5 — 2026-02-06
- 5.0.4 — 2026-02-05
- 5.0.3 — 2026-02-05
- 5.0.2 — 2026-02-05
- 5.0.1 — 2026-02-05
- 5.0.0 — 2026-02-05
- 4.1.1 — 2024-12-16
- 4.1.0 — 2024-12-16
- 4.0.6 — 2024-08-29
- … 95 more at https://npm.io/package/reus.js/versions

## README

# reus.js

reus.js 是面向 Koa 3 应用的轻量二次封装。它统一项目配置、启动任务、请求体解析、Controller/Middleware、路由、代理、Swagger、开发进程和构建流程，让使用方聚焦业务代码。

## 环境与安装

- Node.js 22.22.0+
- Koa 3
- 项目使用 ESM（`package.json` 中设置 `"type": "module"`）

框架源码使用 TypeScript，并在发布前编译到 `dist/`；npm 包仍只运行编译后的 JavaScript，因此现有使用方的 JavaScript 配置、CLI 和导入方式无需调整。纯公共类型位于 `types/index.d.ts`，构建时会随编译产物一并发布。维护框架时可运行：

```bash
pnpm build:framework
pnpm check
```

```bash
pnpm add reus.js
```

## 框架源码结构

- `src/index.ts`：包的运行时公共导出；发布入口仍为 `reus.js`。
- `src/app.ts`、`src/common.ts`、`src/utils.ts`：应用初始化、使用方配置/插件加载和路由注册。
- `src/config/`：框架默认项目配置。
- `src/cli/`：`reus create`、`build`、`launch` 的命令入口、实现及运行模式常量。
- `src/models/`、`src/helpers/`、`src/modules/`：面向应用运行时的模型、上下文 helper 与内置模块。
- `types/index.d.ts`：仅包含公共类型及 Koa 上下文扩展声明；构建时复制到 `dist/types/`。
- `bin/` 和 `.gulpfiles/`：保留为 npm/PM2 入口与 Gulp 任务的稳定源位置。

## CLI

```bash
# 从 starter 创建项目
reus create -t simple

# 开发模式：默认只启动 nodemon
reus launch . --mode dev

# 构建 src 到 dist
reus build .

# 生产模式（launch 的默认模式）
reus launch .
```

命令的子进程失败会返回非零退出码。`create` 会校验下载状态、等待解压完成，并在成功或失败后清理临时文件。

## 最小项目

`project.config.json`：

```json
{
  "app": {
    "port": 8090
  },
  "browserSync": {
    "enabled": false
  }
}
```

`src/app.config.js`：

```js
import routers from './routers.js';
import RequestLog from './middlewares/request-log.js';

export default {
  startups: [
    async () => {
      // 在 Koa 创建和 listen 之前顺序执行
    },
  ],
  middlewares: [RequestLog],
  routers,
  swaggerYmlFile: './swagger.yml',
};
```

`src/routers.js`：

```js
import HelloController from './controllers/hello.js';

export default [
  {
    path: '/hello',
    method: 'get',
    controller: HelloController,
  },
];
```

Controller 与 Middleware：

```js
import { Controller, Middleware } from 'reus.js';

export class HelloController extends Controller {
  async index() {
    this.ctx.json({ message: 'hello' });
  }
}

export class RequestLog extends Middleware {
  async index() {
    console.log(this.ctx.method, this.ctx.url);
    return this.next();
  }
}
```

## 上下文 helper

`ctx.json(value)` 将响应设置为 JSON。

`ctx.http(options)` 基于 Node 原生 `fetch`，支持 `uri/url`、`qs`、`method`、`headers`、`body`、`json`、显式 `timeout` 和 `encoding: null`：

```js
const response = await ctx.http({
  uri: 'http://127.0.0.1:8080/orders',
  method: 'POST',
  body: { side: 'BUY' },
});

// response: { headers, data, status_code }
```

HTTP 4xx/5xx 会 resolve；网络错误和显式超时会 reject。框架不设置默认超时。

## 路由协议

路由始终启用 `allowedMethods`：

- method 不匹配返回 405 与 `Allow`；
- OPTIONS 自动响应；
- 不支持的方法可能返回 501；
- 未知路径保持 404。

正确 method/path 的 Controller 请求不受影响。

## BrowserSync

BrowserSync 与 nodemon 是两个独立工具。默认只启动 nodemon；仅当下面的配置显式开启时，BrowserSync 才并行启动，并代理真实的 `app.port`：

```json
{
  "browserSync": {
    "enabled": true,
    "port": 3001,
    "ui_port": 10000,
    "files": ["src/pages/**/*"]
  }
}
```

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/reus.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
