Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make function calls to remote hosts seamlessly

License

NotificationsYou must be signed in to change notification settings

lindell/remote-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusCoverage Status

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 viaJSON RPC 2.0 which makes it possible to use with other clients. It hasno dependencies and works by utilizingProxies that was introduced with ES6.

Install

npm install remote-function

Example

Server

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

constserver=require('remote-function').createServer();server.divide=(arg1,arg2)=>{if(arg2===0){thrownewError("Can't divide by zero.");}returnarg1/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 withawait if you are within anasync function.

constremote=require('remote-function').createClient({host:'127.0.0.1'});constresult=awaitremote.divide(12,3);console.log(result);// 4

If an error is thrown on the server:

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

Options

Server

OptionDefaultDescription
host"0.0.0.0"The host that the server listen on
port6356The port that the server listen on
includeStacktrueShould errors include the server stacktrace?

Client

OptionDefaultDescription
host"127.0.0.1"The host that the server listens on
port6356The port that the server listens on
headers{}Additional request headers
connectTimeout0The socket connection timeout
responseTimeout0The response wait timeout

createClient also supports options fromhttp.request(). For example, you can setheaders to add extra headers to http request, orauth if you need Basic Authentication. You cannot change http requestmethod.

About

Make function calls to remote hosts seamlessly

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp