How do I receive events from the browser in my node.js code? (e.g: I imagine Mixpanel, kissmetrics, etc do something like this?
thanks
How do I receive events from the browser in my node.js code? (e.g: I imagine Mixpanel, kissmetrics, etc do something like this?
thanks
The same way any other web server receives events from the browser: the browser makes an HTTP request to the URL of your server and the server receives that request. Listening for HTTP requests is the "Hello World" example for node.js.
What you're looking for is http://hummingbirdstats.com/ realtime stats 20 times a second.
You should also checkout socket.io if you haven't. Websockets events are faster than HTTP requests.
You have to send them to your server, via AJAX or some similar method.
Remember, node code runs on the server; the browser runs on the client. The way to get information back and forth from a server to a client running a web browser is an HTTP request.
I recommend dnode. Search for dnode on the browser in the README. It's a quick and complete example of making a RPC. In this case the remote function would be an event handler.
It uses socket.io, which supports websockets, flash sockets, and xhr.