百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

remote-function

> 编程语言
开源

无缝地调用远程主机的函数调用

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

无缝地调用远程主机的函数调用

Remote Function

Remote Function is a library for making remote procedure calls in an intuitive way. Just declare functions on the server and call them from the client, that's it! If the function errors, the error will seamlessly be transferred to the calling client. This is done via JSON RPC 2.0 which makes it possible to use with other clients. It has no dependencies and works by utilizing Proxies that was introduced with ES6.

Install

bash
npm install remote-function

Example

Server

Initiate a server, then just define your function on the server object.

javascript
const server = require('remote-function').createServer();

server.divide = (arg1, arg2) => {
    if (arg2 === 0) {
        throw new Error("Can't divide by zero.");
    }
    return arg1 / arg2;
};

Client

Define where the server is located when creating a client. Then you can just call the function that is defined at the server and you get a promise that returns what the server function will return. If you are on >=Node 8.0.0, you can use it with await if you are within an async function.

javascript
const remote = require('remote-function').createClient({ host: '127.0.0.1' });

const result = await remote.divide(12, 3);
console.log(result); // 4

If an error is thrown on the server:

javascript
try {
    const result = await remote.divide(12, 0);
    console.log(result); // Will not be reached
} catch (error) {
    // Get the error thrown on the server, including stacktrace
}

Options

Server

Option Default Description
host "0.0.0.0" The host that the server listen on
port 6356 The port that the server listen on
includeStack true Should errors include the server stacktrace?

Client

Option Default Description
host "127.0.0.1" The host that the server listens on
port 6356 The port that the server listens on
headers {} Additional request headers
connectTimeout 0 The socket connection timeout
responseTimeout 0 The response wait timeout

createClient also supports options from http.request(). For example, you can set headers to add extra headers to http request, or auth if you need Basic Authentication. You cannot change http request method.

Issues· 6 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptes6-proxiesjson-rpcjson-rpc2rpc

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言