The last part of this article series described the principles of Twitter-like services based on Azure Storage Tables. This part now describes the structure of a new node module which acts as a timeline service. This service can be used very easily in existing node projects.
To integrate this node module just install the azure-timeline-service via node package manager. This integrates everything that is required automatically:
npm install azure-timeline –save
The module allows to post events to a specific user timeline and the timeline of all followers. The following snip-let illustrates it:
var user = azureTimelineService.createSubject(“<>”, “<>”);
user.postEvent(‘login’, { timestamp: new Date() }).then(function() {
console.log(“DONE”);
});
Every method works asynchronous based on promises. Following another user is as simple as posting an event to a timeline
user.follow(user01).then(function() {
console.log(“DONE”);
})
Following a user means all events this user posts to a timeline will be posted to the followers timeline as well. Last but not least loading a timeline is important. The system returns currently all events from a timeline which is a point of change in the future:
user.loadTimeline().then(function(events) {
console.log(events);
})
All samples are implemented in the sample file of the Azure Timeline project here. Any questions? Feel free to open an issue at GitHub or just stay in touch via this block.