5

I know a couple of projects out there like mean.io or meanjs, or even yeoman generators where all the necessary boilerplate stuff when you are going to develop under MEAN stack it's done for you.

The truth is that MEAN stack has been closely coupled with Angular.js and there is no project that do the same with Backbone.js and I'm very surprised with that, I believe it is a very common stack the combination of Mongodb, Express, Backbone and friends like Require.js or Marionette.js.

I've been poking around with that, trying to mix backbone and express yeoman generators, building a skeleton from other people projects but I still keep thinking there has to be a better approach to do that.

I would appreciate it to you guys sharing your experience to figure out what I am missing here.

So the question is: Which are the common practices and tips do you use for starting a full stack "MEBN" (Mongodb, Express and Backbone) project from scratch?

Thanks to all of you!!

2 Answers2

2

Wouldn't it be MEBN? :D

You may have a look at Backbone Boilerplate (BBB): https://github.com/backbone-boilerplate/backbone-boilerplate

It uses node to serve the local application, so there you have a start. ;)

Basically you could also grab a MEAN example, strip Angular out and mix Backbone in. The server (Nodejs) part will be the same (controllers, REST API, JSON format for data exchange), but you'll use Backbone Models and Collections to interact with the API, and Views for UI.

CharlieBrown
  • 4,143
  • 23
  • 24
  • Yep you're right, it would be *"MEBN"* not *"MEBA"*. I've just fixed that ;) Yes I'm with you that definitely a backbone-boilerplate would be a good starting point for the client side of the stack with test-framework stuff an other. If there are no more alternatives, one solution like I said before, would be integrating something like that inside an example of MEAN stack, but I'm still thinking that this would not be an optimal solution because you'll be dealing with two different boilerplate mechanisms at the same time ... – bormansquirrel Oct 16 '14 at 15:47
  • 1
    Perhaps I didn't make my point clear: you don't NEED any boilerplate! Boilerplates are good once you're tired of writing the same thing over and over, and you're expert enough to fine tune the boilerplate to your conventions. If you're looking for js and css minification, template compilation, test infrastructure and so on, BBB is a nice choice. It's just the sum of individual Grunt packages you would end finding by yourself, eventually. And it has a horrible CSS minification bug. ;) – CharlieBrown Oct 16 '14 at 18:21
  • Yeah I know what you mean, but I was asking about all this good practices for building the whole environment when you are going to develop with __"MEBN"__ stack ;) – bormansquirrel Oct 16 '14 at 20:05
0

You can use this MEBN

I think Angular is better than Backbone, personally I use mean.io, but...

Good points

Backbone can be integrated with many third-party template engines, the default choice is Underscore templates. Since Underscore is a Backbone dependency and you already have it on your page, you can easily take advantage of its templating engine without adding any additional dependencies for your application. On the downside, the templating engine of Underscore is very basic and you usually have to throw javascript into the mix, as you can see in our example:

Backbone is lightweight, fast and has a small memory footprint. The learning curve is very linear, and there are only a few simple concepts to grasp (Models/Collections, Views, Routes). It has great documentation, the code is simple and heavily documented, and there is even an annotated version of the code which explains how it works in detail. You can actually go over the entire source code of the framework and get familiar with it in less than an hour.

Being so small and basic, Backbone can be a good foundation to build your own framework upon. Some examples of 3rd party frameworks based on Backbone are Aura, Backbone UI, Chaplin, Geppetto, Marionette, LayoutManager, Thorax, Vertebrae. With Angular and Ember you usually have to live with the choices made by the authors of the frameworks, which may or may not suit your project needs and personal style. Angular 2.0 promises to change it, by comprising small independent modules, so you will be able to pick and mix. We are yet to see if they will be able to deliver this.

Pain Points

Backbone does not provide structure. It rather provides some basic tools you can use to create structure, leaving it up to the developer to decide how to structure his application, and there are also many blanks to fill. Things such as memory management have to be carefully considered. The lack of view lifecycle management makes route/state changes prone to memory leaks unless you take care of cleaning up everything yourself.

While it is true that many of the functions not provided by Backbone itself could be filled by third-party plugins, this also means that there are many choices to be made when creating an application, as many functions have several alternative plugins. For example, nested models can be provided by Backbone.DocumentModel, BackBone.NestedTypes, Backbone.Schema, Backbone-Nested, backbone-nestify, just to name a few. Deciding which one is the best for your project requires research, which in turn takes time — and one of the main purposes of framework is to save you time.

Backbone lacks support for two-way data binding, meaning you will have to write a lot of boilerplate to update the view whenever your model changes, and to update your model whenever the view changes. See the example given above, showing how two-way in Angular.js data binding reduces boilerplate.

Views in Backbone manipulate the DOM directly, making them really hard to unit-test, more fragile and less reusable. The common practice is to look up DOM elements using CSS selectors, so changing a CSS class name, adding a new element with the same class name or even wrapping some DOM tree inside another element can break your CSS selectors and render your app usable.

Christian Cruz
  • 670
  • 8
  • 9
  • 1
    Good Boilerplate reference! Talking about the pros and cons of Backbone & Angular I believe that "Backbone is easier to learn than Angular" but all the boilerplate and decisions you've to take, like you said makes it hard working and a lot of researching too. The truth is you've more freedom but more responsibilities too. Anyway, I don't think that when we talking about JS MV** frameworks the issue is about choosing the one you likes more, like RoR or Django (MVC server-side frameworks). It's more about knowing what good features offers each of them that fits your project requirements. – bormansquirrel Nov 05 '14 at 12:32
  • 2
    Backbone does not lack two-way data binding. Backbone.Stickit and Backbone.ModelBinder are two popular libraries commonly used. I am so tired of all these framework comparisons because none of them really have complete understanding of the frameworks before they compare. You will be fine with either of the frameworks. They all have the features you need, and accomplish the same things in only slightly different ways. I didn't downvote this answer though. :-) – Michael L Jan 09 '15 at 20:13
  • most of this just amounts to a rant against backbone. The link was helpful though. – Phillip Whelan Nov 24 '16 at 14:59