@deco-cx/warp-node

中文文档
0.3.23发布于 2026/05/23MITTypeScriptES Module构建来源已验证近 30 天下载 1.7万

WebSocket tunneling library for Node.js and other runtimes

原始使用文档
文档目录15 节
  1. Installation
  2. Requirements
  3. Server
  4. Usage
  5. Client
  6. Usage
  7. Example Workflow
  8. Server
  9. Client
  10. Runtime Compatibility
  11. TypeScript Support
  12. Troubleshooting
  13. Common Issues
  14. Contributing
  15. License

NPM Version NPM Downloads GitHub License

Warp Node

Warp Node is a simple tool that allows your locally running HTTP(s) servers to have a public URL, serving as an easy-to-self-host alternative to services like ngrok. Warp Node is implemented for Node.js and other JavaScript runtimes with the goal of providing flexibility and minimal dependencies.

The project has two main components:

  • Server: Deployable on a server, it connects to the outside world and is accessible from any domain.
  • Client: Runs locally to connect a given HTTP endpoint running on a local or non-public network.
image

Installation

npm install @deco-cx/warp-node

Requirements

  • Node.js 22+ (for Node.js environments - requires Promise.withResolvers support)
  • Works in Cloudflare Workers, Deno, and other JavaScript runtimes

Server

The Warp server opens a single HTTP port to which the Warp client connects and upgrades to a WebSocket connection. Each request to this HTTP port is forwarded (based on the client's HOST header) to the corresponding connected Warp client connection, which then serves the request.

Usage

To start the Warp server, import the serve function from the Warp package and call it with the appropriate configuration.

Example

import { serve } from "@deco-cx/warp-node";

const port = 8080; // The port where the Warp server will listen
const apiKeys = ["YOUR_API_KEY1", "YOUR_API_KEY2"]; // Array of API keys for authentication

const server = serve({ port, apiKeys });
console.log(`Warp server listening on port ${port}`);

Parameters

  • port: The port number where the Warp server will listen for connections.
  • apiKeys: An array of API keys used for client authentication.

Client

The Warp client connects to the Warp server. Upon connection, the client shares the given API key and the domain it wants to receive requests for.

Usage

To connect a client to the Warp server, import the connect function from the Warp package and call it with the appropriate configuration.

Example

import { connect } from "@deco-cx/warp-node";

const port = 3000; // The local port you want to expose
const domain = "www.your.domain.com"; // The domain name for your service
const server = "wss://YOUR_SERVER"; // The WebSocket URL of your Warp server
const apiKey = "YOUR_API_KEY"; // The apiKey

const { registered, closed } = await connect({
  domain,
  localAddr: `http://localhost:${port}`,
  server,
  apiKey,
});

await registered;
console.log("Client registered successfully");

closed.then(() => {
  console.log("Connection closed");
});

Parameters

  • domain: The domain name that will be used to access your localhost service.
  • localAddr: The local address of the service you want to expose (e.g., http://localhost:3000).
  • server: The WebSocket URL of your Warp server (e.g., wss://YOUR_SERVER).
  • apiKey: The apiKey for connecting to the Warp server.

Return Values

  • registered: A promise that resolves when the client has successfully registered with the server.
  • closed: A promise that resolves when the connection to the server is closed.

Example Workflow

Here’s a complete example of setting up a Warp server and client:

Server

import { serve } from "@deco-cx/warp-node";

const port = 8080;
const apiKeys = ["YOUR_API_KEY1", "YOUR_API_KEY2"];

const server = serve({ port, apiKeys });
console.log(`Warp server listening on port ${port}`);

Client

import { connect } from "@deco-cx/warp-node";

const port = 3000;
const domain = "www.your.domain.com";
const server = "wss://YOUR_SERVER";
const apiKey = "API_KEY";

(async () => {
  const { registered, closed } = await connect({
    domain,
    localAddr: `http://localhost:${port}`,
    server,
    apiKey,
  });

  await registered;
  console.log("Client registered successfully");

  closed.then(() => {
    console.log("Connection closed");
  });
})();

Runtime Compatibility

Warp Node is designed to work across multiple JavaScript runtimes:

  • Node.js 22+: Full support with native HTTP and WebSocket handling
  • Cloudflare Workers: Works with WebSocketPair API
  • Deno: Compatible with Deno's WebSocket implementation
  • Bun: Should work with Bun's WebSocket support

The library automatically detects the runtime environment and uses the appropriate APIs.

TypeScript Support

This package includes full TypeScript definitions. No additional @types packages are needed.

import {
  connect,
  type ConnectOptions,
  type HandlerOptions,
  serve,
} from "@deco-cx/warp-node";

Troubleshooting

Common Issues

  • Invalid API Key: Ensure that the API key you are using is listed in the apiKeys array on the server.
  • Connection Refused: Check that the server is running and accessible at the specified WebSocket URL.
  • Domain Not Accessible: Ensure that the domain name is correctly configured and pointing to the Warp server.
  • Node.js Version: Ensure you're using Node.js 22 or later for full compatibility.

Contributing

This project is open source. Feel free to contribute by submitting issues or pull requests.

License

MIT License - see LICENSE file for details.

版本与发布记录

@deco-cx/warp-node 共发布 11 个版本,首次发布于 2025/07/29;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.23latest2026/05/235 个月前
0.3.21-debug.22025/08/061.3 年前
0.3.21-debug.12025/08/061.3 年前
0.3.21-beta.22025/08/061.3 年前
0.3.21-beta.12025/08/061.3 年前
0.3.202025/08/061.3 年前

关于 @deco-cx/warp-node 的常见问题

@deco-cx/warp-node 是什么?

WebSocket tunneling library for Node.js and other runtimes

如何安装 @deco-cx/warp-node?

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

@deco-cx/warp-node 支持 TypeScript 吗?

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

@deco-cx/warp-node 支持 ESM 还是 CommonJS?

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

@deco-cx/warp-node 需要什么版本的 Node.js?

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

@deco-cx/warp-node 可以商用吗?

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

@deco-cx/warp-node 的下载量有多少?

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

@deco-cx/warp-node 还在维护吗?

最新版本 0.3.23 发布于 2026/05/23(5 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 1 个;首次发布于 2025/07/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。