Reputation: 45
I have the following code.Instead of value of url: 'http://isaacs.couchone.com/registry/_all_docs', i need to specify an ip address of a local machine ,say 10.30.52.75 and a port number 3000,where my application is running.How to specify ip address and port number using node.js as a value of url, with out affecting the working of the remaining source code.
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
}))
Upvotes: 1
Views: 545
Reputation: 1235
Assuming the host IP is 10.30.52.75 and the host port is 3000, your code snippet becomes:
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
}))
Upvotes: 2