zerorpc: how to convert string data from python to node
<p>I need to call a python script from <a href="https://nodejs.org/en/" rel="nofollow">nodejs</a> and getting back the result. I found the <a href="http://www.zerorpc.io" rel="nofollow">zerorpc</a> library which seems a good fit. The python script returns an array of strings but in node i got objects of binary data.</p>

<p>This is the python zerorpc server:</p>

<pre><code># python zerorpc server

import zerorpc

class HelloRPC(object):

    def test(self):
        return ["A", "B", "C"]

server = zerorpc.Server(HelloRPC())
serrver.bind("tcp://0.0.0.0:4242")
server.run()
</code></pre>

<p>This is the node zerorpc client:</p>

<pre><code>// nodejs zerorpc client

var zerorpc = require("zerorpc")    

var client = new zerorpc.Client();
client.connect("tcp://127.0.0.1:4242");

client.invoke("test", function(error, response, more) {
    if (response) {
        for (var i = 0; i &lt; response.length; i++) {
            console.log(typeof response[i], response[i])
        }
    }
}
</code></pre>

<p>Which gives this output:</p>

<pre><code>object &lt;Buffer 41&gt;
object &lt;Buffer 42&gt;
object &lt;Buffer 43&gt;
</code></pre>

<p>Which is the best way to convert these objects in strings in nodejs?</p>

<p>Node JS Buffer class has the toString method</p>

<pre><code>strings[i] = response[i].toString("utf8")
</code></pre>

<p>See the method:
<a href="https://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end" rel="nofollow">https://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end</a></p>

python node.js string binary zerorpc