我有以下代码。而不是url:'http://isaacs.couchone.com/registry/_all_docs'的值,我需要指定本地机器的IP地址,比如10.30.52.75和端口号3000,我的应用程序正在运行。如何使用node.js指定ip地址和端口号作为url的值,而不影响剩余源代码的工作。
var request = require('request');
var JSONStream = require('JSONStream');
var es = require('event-stream');
var mqtt = require('mqtt');
var client = mqtt.createClient();
request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
.pipe(JSONStream.parse('rows.*'))
.pipe(es.mapSync(function (data) {
client.publish('NewTopic',JSON.stringify(data));
client.on('connect', function() {
client.end();
});
console.error(data);
return data
}))
答案 0 :(得分:2)
假设主机IP为10.30.52.75且主机端口为3000,则代码段变为:
var request = require('request');
var JSONStream = require('JSONStream');
var es = require('event-stream');
var mqtt = require('mqtt');
var client = mqtt.createClient();
var url = 'http://10.30.52.75:3000';
request({url: url})
.pipe(JSONStream.parse('rows.*'))
.pipe(es.mapSync(function (data) {
client.publish('NewTopic',JSON.stringify(data));
client.on('connect', function() {
client.end();
});
console.error(data);
return data
}))