# @eik/service 中文文档

规范地址：https://npmcn.com/package/%40eik/service/

版本：5\.6\.15
npm 元数据更新时间：2026-11-09T05:41:38.629Z
中文译文更新时间：2026-11-14T06:44:37.230Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40eik/service
原文对照：https://npmcn.com/package/%40eik/service/?lang=original
项目主页：https://github.com/eik-lib/service#readme
源码仓库：https://github.com/eik-lib/service

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：214 kB，11 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=20\.5\.0
- 运行依赖：12 个
- 首次发布：2020-04-16T17:07:23.393Z
- 最新版本发布：2026-11-09T05:41:38.266Z
- 近 30 天下载量：2221（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：491（近 12 个月 98 个）

## 中文简介

Eik REST API 作为独立的 HTTP 服务

## 安装

```sh
npm install @eik/service
```

也可以使用：`pnpm add @eik/service`、`yarn add @eik/service`、`bun add @eik/service`

## README

# @eik/服务

这是 [HTTP 服务器](https://eik.dev/docs/server/) 运行 Eik 服务 . 执行《公约》和 [HTTP 终点](https://eik.dev/docs/server/http-api) 包含 [`@eik/core`](https://github.com/eik-lib/core#readme)。 。 。 .

## 安装

```
npm install @eik/service
```

## 使用量

此服务器可以作为节点可执行文件运行,也可以作为快取插件运行.

### 国 际

使用您的配置旋转内置快取服务器 `config/` 文件夹,或来自环境变量.

```sh
npx @eik/service
```

### 快捷插件

对于生产设置,建议采用快取插件方法.

```js
import fastify from 'fastify';
import Service from '@eik/service';
import SinkGoogleCloudStorage from '@eik/sink-gcs';

// Set up the Google Cloud Storage sink
// https://github.com/eik-lib/sink-gcs?tab=readme-ov-file#example
const sink = new SinkGoogleCloudStorage({
    credentials: {
        client_email: 'a@email.address',
        private_key: '[ ...snip... ]',
        projectId: 'myProject',
    },
});

// Set up the Eik service as a plugin
const service = new Service({ sink });

// Set up Fastify
const app = fastify({
    ignoreTrailingSlash: true,
    modifyCoreObjects: false,
    trustProxy: true,
});

// Register the Eik service in Fastify
app.register(service.api());

// Start the server
const run = async () => {
    await service.health();
    await app.listen(
        service.config.get('http.port'),
        service.config.get('http.address'),
    );
};

run();
```

以上例子显示了谷歌云存储槽. 你也可以使用这个 [文件系统槽](https://github.com/eik-lib/sink-file-system),或执行 [槽接口](https://github.com/eik-lib/sink) 用于您的自定义存储后端.

## 常见问题

### @eik/service 是什么？

Eik REST API 作为独立的 HTTP 服务

### 如何安装 @eik/service？

在项目目录运行 npm install @eik/service，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 service、eik-server、eik-service，可以用 npx service 直接运行。

### @eik/service 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @eik/service 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @eik/service 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=20\.5\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @eik/service 可以商用吗？

@eik/service 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @eik/service 的下载量有多少？

根据 npm 官方下载统计，@eik/service 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,221 次，日均约 74 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @eik/service 还在维护吗？

最新版本 5\.6\.15 发布于 2026/11/09（5 天前）；至今共发布 491 个版本，其中过去 12 个月发布了 98 个；首次发布于 2020/04/17。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

