@gravity-ui/nodekit

中文文档
2.22.1发布于 2026/11/09MITTypeScriptCommonJS近 30 天下载 3.3万

Simple toolkit for your Node.js apps and scripts

原始使用文档
文档目录11 节
  1. Install
  2. Getting started
  3. Documentation
  4. Contributing
  5. Getting started
  6. License
  7. For AI agents
  8. When to use
  9. When not to use
  10. Common pitfalls
  11. Documentation for AI agents

NodeKit

NodeKit is a simple toolkit for your Node.js apps, scripts and libraries. It provides functionality for logging, telemetry, configuration and error handling, so you can have familiar foundation in your different projects.

Install

npm install --save @gravity-ui/nodekit

Getting started

Add dependency to your project:

npm install --save @gravity-ui/nodekit

And then import and init NodeKit in your application:

import {NodeKit} from '@gravity-ui/nodekit';

const nodeKit = new NodeKit();
nodekit.ctx.log('App is ready');

Documentation

See docs/ directory for additional documentation:

  • docs/configuration.md specifies how you can configure both nodekit itself and your nodekit-based applications
  • docs/contexts.md describes concept of NodeKit contexts, logging and tracing
  • docs/app-error.md contains description of useful custom error class they NodeKit provides for your applications
  • docs/utils.md lists some additional helper functions that are bundled with NodeKit

Contributing

Getting started

Grab a copies of NodeKit repository and example applications:

git clone [email protected]:gravity-ui/nodekit
git clone [email protected]:gravity-ui/nodekit-examples

Link your nodekit to npm and start a compiler:

cd nodekit && npm link && npm run dev

Then, in another terminal, go to examples, open the one that you're interested in, link your nodekit there, then start the app:

cd nodekit-examples/basic-app && npm i && npm link @gravity-ui/nodekit
npm run dev

At this point you can make changes both to NodeKit and demo app, and see results in real time.

License

Distributed under the MIT License. See LICENSE for details.

For AI agents

A foundational Node.js toolkit (logging, telemetry, typed errors, config, request contexts) shared across Gravity UI backends — reach for it to get a consistent app spine before adding any HTTP layer, instead of assembling logging/error/config plumbing yourself.

When to use

  • Any Node.js service/script that wants shared logging, telemetry (tracing), and a typed AppError.
  • Providing request-scoped context (logs/traces) across async boundaries.
  • Centralizing configuration so multiple services in the same ecosystem behave consistently.

When not to use

  • To expose HTTP routes, middleware, or a server, use @gravity-ui/expresskit — it builds on top of NodeKit and adds the Express/HTTP layer.
  • For a standalone, single-file script with no logging/telemetry needs, plain Node APIs are lighter than the full NodeKit context system.

Common pitfalls

  • Hallucinating import {Logger} / logger — logging is reached through the NodeKit context: new NodeKit() then nodekit.ctx.log(...), not a standalone logger export.
  • Instantiating NodeKit repeatedly — create one NodeKit instance per app and share its ctx; creating many instances fragments logging/telemetry config.
  • Throwing plain Error — use the bundled AppError (see docs/app-error.md) so error codes and telemetry are captured consistently.
  • Skipping config initialization — NodeKit reads configuration on construction; review docs/configuration.md before assuming defaults.

Documentation for AI agents

Agent-readable documentation for the installed version is located in node_modules/@gravity-ui/nodekit/dist/docs/INDEX.md.

版本与发布记录

@gravity-ui/nodekit 共发布 53 个版本,首次发布于 2023/02/22;过去 12 个月发布了 19 个版本。

版本发布日期距今
2.22.1latest2026/11/097 天前
2.21.02026/10/3017 天前
2.20.12026/10/1829 天前
2.20.02026/10/131 个月前
2.19.02026/10/131 个月前
2.18.12026/09/171 个月前

关于 @gravity-ui/nodekit 的常见问题

@gravity-ui/nodekit 是什么?

Simple toolkit for your Node.js apps and scripts

如何安装 @gravity-ui/nodekit?

在项目目录运行 npm install @gravity-ui/nodekit,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:axios(^1.7.7)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gravity-ui/nodekit 支持 TypeScript 吗?

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

@gravity-ui/nodekit 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@gravity-ui/nodekit 需要什么版本的 Node.js?

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

@gravity-ui/nodekit 可以商用吗?

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

@gravity-ui/nodekit 的下载量有多少?

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

@gravity-ui/nodekit 还在维护吗?

最新版本 2.22.1 发布于 2026/11/09(7 天前);至今共发布 53 个版本,其中过去 12 个月发布了 19 个;首次发布于 2023/02/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。