@amplitude/node

中文文档
1.10.2发布于 2022/09/08MITTypeScriptESM + CJS近 30 天下载 130.6万

Offical Amplitude SDK for Node.js

原始使用文档
文档目录4 节
  1. Installation and Quick Start
  2. Node and JS SDK's
  3. Retry Behavior
  4. Need Help?


npm version

Official Amplitude SDK for Node.js

This is Amplitude Node.js SDK written in Typescript, the 1st backend SDK for Amplitude. Currently, it's in beta version, but we would like to hear your ideas too! At this moment, we keep it minimal and simple because we want to give more thoughts over different customers' needs. Modularization and flexiblity will be the main priorities for this SDK.

Installation and Quick Start

Please visit our :100:Developer Center for instructions on installing and using our the SDK.

Node and JS SDK's

There might be confusion about the use case and motivations for building the Node SDK when we have a JS SDK. The Amplitude-Javascript SDK is meant to be run in browser environments and on client devices, resulting in very different designs and assumptions. For example, the Javascript SDK contains functionality that interfaces specifically with Web APIs (e.g. referrer and UTM attribution information, navigator.language), and that it can store metadata in API's such as cookies and localStorage. It also makes other assumptions, such as that there is only one active "identity" sending events at a time.

In contrast, the Node SDK is meant to be run in a Node environment, and kept as flexible and modular as possible as to accommodate the various different use cases it may be used in. It makes fewer assumption on how many users it is processing and what is available. Though we primarily foresee the Node SDK being used in server environments, we would love to hear how you plan to use it!

Retry Behavior

One of the important aspects and functionalities of the Node SDK is its ability to retry event payloads that fail. Network requests can fail for a variety of reasons, and it is important that the SDK provides a layer of robustness and correctness when these failures happen.

By default, the Node SDK will retry events on loop after a short pause if it finds that a request has failed; however, this strategy is not ideal for every use case. As such, you can provide your own retryClass that implements the exported Retry interface (currently a single sendEventsWithRetry function). For example, there is a secondary OfflineRetryHandler that is meant for a more opinionated use case where network requests may not always be available for long periods of time:

import { init, OfflineRetryHandler } from "@amplitude/node"

const amplitudeClient = init('YOUR_API_KEY', { retryClass: new OfflineRetryHandler('YOUR_API_KEY') })

As well as a BaseRetryHandler that does no retrying at all but contains several helper functions to extend from.

Need Help?

If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Amplitude Help.

版本与发布记录

@amplitude/node 共发布 40 个版本,首次发布于 2020/05/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.10.2latest2022/09/084 年前
1.10.12022/08/304 年前
1.10.02022/04/014 年前
1.9.22022/02/014 年前
1.9.12021/11/114 年前
1.9.02021/10/155 年前

关于 @amplitude/node 的常见问题

@amplitude/node 是什么?

Offical Amplitude SDK for Node.js

如何安装 @amplitude/node?

在项目目录运行 npm install @amplitude/node,或使用 pnpm add / yarn add / bun add。

@amplitude/node 支持 TypeScript 吗?

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

@amplitude/node 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@amplitude/node 需要什么版本的 Node.js?

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

@amplitude/node 可以商用吗?

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

@amplitude/node 的下载量有多少?

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

@amplitude/node 还在维护吗?

最新版本 1.10.2 发布于 2022/09/08(4 年前);至今共发布 40 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/05/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。