Node: Difference between revisions

From Open Rail Data Wiki
Created page with "// Remember to enable the feed you are trying to subscribe in the network rail web application. var prettyjson = require('prettyjson'), StompClient = require('stomp-client..."
 
No edit summary
Line 1: Line 1:
// Remember to enable the feed you are trying to subscribe in the network rail web application.
== node.js ==
 
Remember to enable the feed you are trying to subscribe in the network rail web application.
 
<pre>
var prettyjson = require('prettyjson'),
var prettyjson = require('prettyjson'),
     StompClient = require('stomp-client').StompClient;
     StompClient = require('stomp-client').StompClient;
Line 12: Line 17:
     });
     });
});
});
</pre>

Revision as of 23:26, 8 October 2012

node.js

Remember to enable the feed you are trying to subscribe in the network rail web application.

 
var prettyjson = require('prettyjson'),
    StompClient = require('stomp-client').StompClient;

var destination = '/topic/TRAIN_MVT_ALL_TOC',
    client = new StompClient('datafeeds.networkrail.co.uk', 61618, 'emailaddress', 'your_password', '1.0');

client.connect(function(sessionId) {
    console.log('Trying to connect...');
    client.subscribe(destination, function(body, headers) {
        console.log(prettyjson.render(JSON.parse(body)));
    });
});