Copyright ©

Mongoose OS Forum


A node.js client library for RPC

PKGeorgievPKGeorgiev Sofia
edited October 2017 in Mongoose OS

Hi everyone,

I've created a nodejs library for calling functions via RPC (http/ws/mqtt):
Here's how to use:

const Rpc = require("mongoose-os-rpc").Rpc;

// Instantiate Rpc object using the short format (specifying address property)
// The Rpc object will internally create an instance of an appropriate transport
let rpc = new Rpc({
  address: 'http://deviceIpOrName/rpc'
  // OR: address: 'ws://deviceIpOrName/rpc'
  // OR: address: 'mqtt://deviceIpOrName/esp8266_C6D764'  <-- In this case esp8266_C6D764 is device's name as configured in Mongoose OS

// Subscribe for error events
rpc.on('error', function(){
  console.log("RPC ERROR");

// Subscribe for disconnect events
rpc.on('close', function() {
  console.log("RPC channel was closed!");

// Subscribe for connect events
// To distinguish between connect and reconnect use isReconnect() function
rpc.on('open', function() {
  console.log("RPC channel was opened!");

    if (!rpc.isReconnect()) {"FS.List", {}, "", function(err, result, tag){

        console.log("CALLBACK (FS.List)");

        if (err) {
          // Oops, something went wrong
        } else {


    } else {
      console.log("The underlying transport had reconnected");


It is still Beta and will be published to npm registry soon. Be welcome to test, report bugs or make suggestions :)

Sign In or Register to comment.