Search code examples
angularjsnode.jsmongodbbackbone.jssails.js

How to create a dynamic front end based on Node JS, MongoDB, Sails JS


Basically I'm writing an app and am using Sails, MongoDB and Node JS for the back end. I'll use Sail's API features and was wondering what would be the best way to make the app realtime.

For instance I could use AJAX to call the API and manipulate the DOM using jQuery and update the DB through $.post then let the model update the db in the backend, however I'm finding this approach quite cumbersome. Not to mention I can see the code could become quite difficult to maintain after a while.

I've been doing some research and - if I understood correctly - it seems I could use either Backbone, Angular or Knockout to manipulate the data/DOM on the front end, however I'm not sure what would be the best approach in my case nor whether any of these would indeed suit my needs:

  • Being able to get the data dynamically
  • Update the data and the DOM dynamically as the user interact with the page
  • Post the updated data dynamically with none or as minimal data transformation on the back end as possible
  • All the above asynchronously

As I don't want this to become a heated debate on which library is best, so I would like to know only whether any of the aforementioned libraries can do what I need and which is the leanest/simplest/has the lighter learning curve.


Solution

  • I did similar research a while ago and when found AngularJS, just stopped looking any further.

    Right to your questions:

    Being able to get the data dynamically

    It is pure pleasure to do it in Angular. For the very basic functionality you have got $http service which allows you to send http request and register a callback when the data arrives. For more complicated things there are modules ngResource and Restangular (external).

    Update the data and the DOM dynamically as the user interact with the page

    For manipulating DOM, Angular introduced concept of directive. It is basically future of the web (Shodow DOM and Web Components) right now. At this time point, there is nothing more elegant out there.

    Post the updated data dynamically with none or as minimal data transformation on the back end as possible

    Yes. JSON.

    All the above asynchronously.

    Yes, of course.