I am very new to node js. I am trying to create a simple coap client and server using node js. I could create a server on which a text file resides. I want to access that from the client.
var coap = require('coap');
var str = "";
var req = coap.request("coap://localhost:5683");
req.on("response", function(chunk){
str +=chunk;
console.log(str);
chunk.pipe(process.stdout);
});
This code is giving me the output as [object Object]. How do I get the string form of this.
I am very new to node js. I am trying to create a simple coap client and server using node js. I could create a server on which a text file resides. I want to access that from the client.
var coap = require('coap');
var str = "";
var req = coap.request("coap://localhost:5683");
req.on("response", function(chunk){
str +=chunk;
console.log(str);
chunk.pipe(process.stdout);
});
This code is giving me the output as [object Object]. How do I get the string form of this.
Share Improve this question edited Jul 24, 2015 at 6:22 mido 25.1k15 gold badges99 silver badges122 bronze badges asked Jul 24, 2015 at 6:00 AngelaAngela 411 gold badge1 silver badge2 bronze badges2 Answers
Reset to default 5You can use JSON.stringify
and JSON.parse
to do that. Here the documentation.
for general purpose :
JSON.stringify(obj);
if object includes functions :
require("util").inspect(obj);
read it here : https://nodejs/en/knowledge/getting-started/how-to-use-util-inspect/