- Notifications
You must be signed in to change notification settings - Fork3
Make function calls to remote hosts seamlessly
License
lindell/remote-function
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
npm install remote-functionInitiate 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;};
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}
| 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? |
| 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 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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.