# @zenweb/core

> ZenWeb Core Module - Module loader and Server

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

## Install

```sh
npm install @zenweb/core
pnpm add @zenweb/core
yarn add @zenweb/core
bun add @zenweb/core
```

## Health

**Score 50/100 (C)** — status: active.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.5.0 |
| Published | 2026-07-22 |
| First published | 2021-03-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.13.0 |
| Dependencies | 2 |
| Unpacked size | 26.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | YeFei |
| Maintainers | yefei777 |
| Keywords | web, app, http, framework, koa |

## Links

- npm: https://www.npmjs.com/package/@zenweb/core
- Homepage: https://zenweb.node.ltd
- npm.io page: https://npm.io/package/@zenweb/core

## Dependencies (2)

- [koa](https://npm.io/package/koa.md) ^2.16.4
- [debug](https://npm.io/package/debug.md) ^4.4.3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 5.5.0 (latest) — 2026-07-22
- 5.4.0 — 2026-04-22
- 5.3.0 — 2026-04-20
- 5.2.1 — 2025-12-11
- 5.2.0 — 2025-12-10
- 5.1.0 — 2024-10-08
- 5.0.0 — 2024-09-25
- 4.3.2 — 2024-07-08
- 4.3.1 — 2024-01-09
- 4.3.0 — 2024-01-05
- 4.2.3 — 2024-01-04
- 4.2.2 — 2024-01-04
- 4.2.1 — 2024-01-03
- 4.2.0 — 2024-01-03
- 4.1.5 — 2024-01-03
- … 53 more at https://npm.io/package/@zenweb/core/versions

## README

# core - 核心

核心模块用于模块的加载与服务启动

## 依赖模块

无

## 配置项

| 配置项 | 类型 | 默认值 | 功能 |
| ----- | --- | ----- | ---- |
| env  | string | development | 执行环境，开发环境为 `development` 生产环境为 `production`，一般通过 NODE_ENV 环境变量指定
| keys | string[] | 无 | Cookie 签名密钥
| proxy | boolean | false | 信任代理头信息，例如前级为 Nginx 为了取得真实客户端 ip 地址需要设置为 `true`
| subdomainOffset | number | 无 | 子域名位置
| proxyIpHeader | string | X-Forwarded-For | 代理后客户端真实 ip 头字段名
| maxIpsCount | number | 0 | 多级代理后允许的 ip 数量，0 无限制

## Core 挂载项

| 挂载项 | 类型 | 功能 |
| ----- | --- | ---- |
| name | string | 应用名称，获取顺序: env.APP_NAME、hostname
| startTime | number | 启动时间: 毫秒时间戳
| app | Koa | 取得 Koa 实例
| loadedModules | LoadedModule[] | 已载入的模块
| server | Server | 取得 http.Server 实例
| debug | Debugger | core debug 方法

## Context 挂载项

| 挂载项 | 类型 | 功能 |
| ----- | --- | ---- |
| core | Core | Core 模块实例

## 全局方法

| 名称  | 功能 |
| ----- | ---- |
| $initCore | 初始化全局 Core 对象
| $getCore | 取得全局 Core 对象
| $getContext | 取得当前请求上下文对象
| $core | 等于 $getCore()
| $ctx | 等于 $getContext(true)
| $debug | 输出 debug 信息支持上下文请求并打印所在行信息

## 自定义模块入口样例代码

```typescript
import { SetupFunction } from '@zenweb/core';

// 自定义模块配置项
export interface MyModOption {}

// 是否有 opt 参数或者其他参数由模块开发者自定义
export default function (opt?: MyModOption): SetupFunction {
  // 返回函数的名称将作为模块名称显示
  return function mymodname(setup) {}
}
```

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