Is there a reason not to use Backbone.Model on the node.js backend?

I thought ... when I code a web application using Backbone.js , most of the time I duplicate models: one version for the backend in X using ORM Y , one for the interface using Backbone. Lots of common checks, same sh * t for generating urls, etc. I just started with Node.js and I thought that since you can run a lot of the same code on the backend and interface, why not use Backbone.js for the backend as well so that there is less code duplication? I could not find information about this ... any pointers? This is a bad idea and why? I can only guess that in this case you will have to write your Backbone.sync to save the database.

EDIT

Practical problems that must be solved to achieve this:

  • Backbone.sync for working with mongodb (or any other database).
  • creating a client javascript file with node.js files, possible solution: browserify
+4
source share
2 answers

After trying to create a backend using Backbone while, I found this to be a complete excess, and brought more problems than simplifications. Instead, I returned to using simple wrappers around mongodb .

My initial thought in using Backbone was sharing URL generation and model checking between the backend and the interface. But in fact for this you do not need the Highway. So I wrote reusable functions for validating and generating URLs and used browserify to make them available on the client side.

Of course, this may change in the future if more and more people create tools for the Backbone backend-side ... but at the time of writing Backbone is definitely not for this, and there is no library to help adapt it.

+1
source

A bit outdated, but interesting nonetheless: Reusing Backbone.js models on a server with Node.js and Socket.io to create real-time applications

A library that will replace the default Backbone.sync by staying on couchDB when using Backbone on Node.js: node-backbone-couch

0
source

Source: https://habr.com/ru/post/1437574/


All Articles