Use node.js for event updates in Django?

I'm not looking for anyone to encode an answer, but I was wondering if anyone could just give a general overview of how to use Django with node.js to receive instant event-driven updates.

I have a news feed and I would like this feed to be updated when new items appear. The general idea is to simply open a connection to the node server through javascript, the node server is "sleeping" until a new element appears, after which it returns data, and the Django side starts another connection.

My confusion arises when it comes to writing node.js code - the documentation has a lot of information, but not about how to use this information. I would appreciate if someone could direct me to where to look for this - am I using something like EventEmitter? How can I on the Django script side request the node server to listen only for events related to a specific user?

Thanks in advance!

+5
source share
2 answers

Nevermind, I think I figured it out. I created my own emitter, and he listened to my own events.

var myemitter = new events.EventEmitter();

And when the request came in from Django,

myemitter.addListener('action'+userid,function(data){
    //do something with data
}

$.ajax() JavaScript, , - . - , -, node. :

myemitter.emit('action'+userid,data);

..., . , , Django script.

, -, , .

+7

node.js, Python-, HTTP-.

- , Django (, http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/). CPU/ , node.js, !

+2

All Articles