在节点红色流中使用节点模块bignum

时间:2015-06-30 08:22:53

标签: javascript node.js node-red

我正在尝试在节点红色流中的函数中使用节点模块bignum。我已将节点模块安装在settings.js所在的文件夹中。我已经编辑了settings.js以包含

functionGlobalContext: {
   bignum:require('bignum')
},

我的功能看起来像这个

var bignum = context.global.bignum;

var b = bignum('782910138827292261791972728324982')
    .sub('182373273283402171237474774728373')
    .div(8)

msg.payload = b;

return msg;

由于某种原因,它只返回此

[msg.payload] : object
{}

1 个答案:

答案 0 :(得分:0)

bignum作为msg.payload传递,它只是在调试面板中没有正确呈现

可以使用以下流程检查

[{"id":"4559ab0b.848204","type":"function","name":"","func":"var bignum = context.global.bignum;\n\nvar b = bignum('782910138827292261791972728324982')\n    .sub('182373273283402171237474774728373')\n    .div(8);\n\nmsg.payload = b;\n\nconsole.log(\"%j\", msg.payload);\nconsole.log(\"%j\", b);\nconsole.log(b);\nconsole.log(\"%j\", msg);\n\nreturn msg;","outputs":1,"noerr":0,"x":413,"y":186,"z":"6dffe97f.085fd8","wires":[["152e806f.249de8"]]},{"id":"28153711.bd78f","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":203,"y":140,"z":"6dffe97f.085fd8","wires":[["4559ab0b.848204"]]},{"id":"62001fd9.03c0c8","type":"debug","name":"","active":true,"console":"false","complete":"false","x":712,"y":191,"z":"6dffe97f.085fd8","wires":[]},{"id":"152e806f.249de8","type":"function","name":"","func":"console.log(\"2\");\nconsole.log(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":543,"y":256,"z":"6dffe97f.085fd8","wires":[["62001fd9.03c0c8"]]}]

我打开一个问题,看看here

更新

这很可能是因为bignum没有实现toString方法,因此Node-RED不知道如何呈现输出。解决此问题的最佳方法可能是提出bignum而非Node-RED的问题。

更新2

Node-RED问题有最新信息

https://github.com/node-red/node-red/issues/690