user3599
user3599

Reputation: 45

How to specify ip address of a local machine and a port number in node.js

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

Answers (1)

manu2013
manu2013

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

Related Questions