如何在mqtt nodejs中查看std中的控制台日志输出

时间:2018-03-05 20:39:51

标签: javascript node.js mqtt

以下是我的代码,我希望在stdout中看到日志。我的客户端正在接收发布消息,只是回显给服务器。我想在python中处理收到的消息,以便我想存储该值。如何在stdout上获取消息值

var mqtt = require('mqtt');
var client  = mqtt.connect('mqtt://127.0.0.1',{
username: process.env.TOKEN
});

client.on('connect', function () {
console.log('connected');
client.subscribe('v1/devices/me/rpc/request/+')
 });

client.on('message', function (topic, message) {
console.log('request.topic: ' + topic);
console.log('request.body: ' + message.toString());
var requestId = topic.slice('v1/devices/me/rpc/request/'.length);
//client acts as an echo service
client.publish('v1/devices/me/rpc/response/' + requestId, message);

 });

1 个答案:

答案 0 :(得分:0)

您可以使用用于此目的的gulp.watch() https://nodejs.org/api/process.html#process_process_stdout