Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing Real-Time apps with NodeJS

im looking forward to build RT web apps with NodeJS. Coming from Rails, I've felt in love with NodeJS and Async JS programming.

Run a few experiments with Node, and then as I search tools and resources to get used with, I got overwhelmed with the lot of stuff over there.

I found lot's of libraries and components over there, and pretty much got confused on how a large-scale well-writen and implemented RT web app should be built.

So the app will run over NodeJS, using Express framework.

I read about knockout.js, a client-side library to provide realtime stuff like automatic UI refresh, and I guess I could conbine it with jQuery. Also, I found socket.io. The author says: Socket.IO aims to make realtime apps possible in every browser and mobile device, blurring the differences between the different transport mechanisms. It's care-free realtime 100% in JavaScript. So socket.io is about compatibility. What about backbone.js? Where does it goes to?

With so much stuff, I got shocked. What should I learn? Which modules worth studing? Im focusing on NodeJS and Express but most books/screencasts covers old versions of nodejs. So im being guided by its official API. Now im here asking your advice and to organize somehow all the info out there. Correct me if my assumptions are not precise, please point me to the right direction and feel free to suggest any other module that could help on my learning.

Thanks in advance

like image 257
jviotti Avatar asked Sep 25 '12 02:09

jviotti


1 Answers

It might be useful for you to separate the node.js server side libraries (via npm etc...) from all of the client side (browser) libraries and technologies like jquery, backbone, knockout etc... when you think about it. Even socket.io which exposes a persistent socket connection between the browser and the server (to avoid polling) does not dictate what client side technologies you use.

Focus on exposing a solid web-api ( random example ) from your server and your client technologies can be swapped, augmented etc... with no effect on the server. The only place they intersect is if you're using a view technology like Jade. It's also an option to have a pure separation where the server is just serving up the client files and your client is a thicker javascript application (using knockout, jquery etc...) calling a good server web api.

Some folks try to unify the client and server models - for example, this article using backbone and node. It depends on how much data you work with to say whether that's feasible but it does couple the client and server and makes the server stateful which can have downsides (scale out, requires affinity etc...). Personally, I get wary of that much magic (binding, state, syncing etc...). Node is about keeping things simple, light and fast. It's a fast front end network server.

My 2 cents (and some may disagree). Start with node on the server and pick your storage (mongoDb etc...). Design a solid RESTful (hypermedia) API - a good webapi regardless of the client. Then start with a basic html/css/js, maybe jquery client and add things like knockout etc... as you expand your client skills. That will allow you to replace your client technologies independent of your server as the new technology winds change (and they will).

That's the hallmark of a well designed system - the ability to replace componets/sub-systems without rewriting everything :)

Hope that helps clear up some of the fog :)

like image 166
bryanmac Avatar answered Sep 24 '22 11:09

bryanmac