admin管理员组文章数量:1357281
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/
本文标签: javascriptHow do I convert object to string in node jsStack Overflow
版权声明:本文标题:javascript - How do I convert object to string in node js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744026794a2578185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论