With node.js, do you actually write your business logic in js or it makes calls to your service layer?

Problem

When using node.js to e.g. serve requests for a backbone.js front end, would node.js actually have your applications business logic or would it make calls out to your web service backend written in say Rails or Java?

If it makes calls out to Rails/Java, how would this be done? Confused as it is single threaded.

Problem courtesy of: loyalflow

Solution

Your business logic will be written in Javascript. I use Node.js + Backbone.js in conjunction with each other on two different projects. Node is great for writing a backend ReSTful API quick and easy and Backbone.js is great for keeping my client side logic organized.

Like any web tech, a separation between client/server is still essential, but Node allows you to think/write in one language and use the same libraries both server and client side. There are many advantages to this in small shops, as the there is no longer a divide between the "front end" guys and the "back end" guys.

Node's single threaded nature is a turn off to a lot of new comers... its easily overcome with multiple proc instances and a load balancer. (If you even need all that... Node is built on an event model and can handle quite the load before you need to think about running another instance... of course this is completely dependent upon if you're writing good asynchronous code)

Is this to say Node.js + Backbone.js is the best answer for YOUR project? No. But you should weigh out the advantages of using Node over Rails/Java/PHP/Python before you make a decision. For me it was simple when considering RAD... one language, one set of libs... its my favorite web stack thus far.

Solution courtesy of: srquinn

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.