RingLinkRingLink
Node.js

将 Node.js 服务暴露到 RingLink

RingLink Node.js SDK 是一个库,允许您将 RingLink 网状网络功能嵌入到您的 Node.js 应用程序中。 您可以通过编程方式连接到您的 RingLink 网络,例如, 访问网络上的其他设备或将本地服务发布到 RingLink 网络。

RingLink SDK 基于用户空间 TCP/IP 堆栈构建, 开发人员无需修改系统网络设置或需要提升权限。 这使得连接到现有 RingLink 网络变得灵活。

当前的 RingLink Node.js SDK 处于 alpha 阶段。 其功能不完整,API 可能会发生变化。

功能特性

  • IPv4
  • IPv6(隧道中)
  • 传入 TCP 代理
  • TCP 服务器和客户端
  • UDP

开始使用

Using the RingLink SDK in Node.js is very easy, just install the @ringlink-sdk/core package.

npm install @ringlink-sdk/core
pnpm install @ringlink-sdk/core
yarn add @ringlink-sdk/core

Requirements

Before using the RingLink Node.js SDK, please ensure you meet the following requirements:

  • Node.js
  • A Config Key

Example

Publish a local service to the RingLink network via proxy:

import { createRinglink } from "@ringlink-sdk/core";
const stack = await createRinglink({
  network: "53cd98d2",
  token: "<your-config-key>"
});

const handle = stack.proxy("tcp", "0.0.0.0:80", "127.0.0.1:8000");
// run your server here, typically a web server run forever


// call handle.stop() to stop the proxy

In this code, a RingLink instance is first created using the createRinglink function, passing your config key and network ID. Then, RingLink.proxy is used to create a proxy tunnel. The first parameter is protocol, only tcp are supported now, second is the local address and port to listen on (usually 0.0.0.0), and the last is the address and port of the service to be published.

When this code runs, RingLink automatically creates a TCP proxy tunnel. Other devices on the current RingLink network accessing <private-ip>:80 will be forwarded to the local 127.0.0.1:8000.