Reputation: 7802
I was thinking ... when I code a web app using Backbone.js
, most of the time I duplicate the models : one version for the backend in language X
, using ORM Y
, one for the frontend using Backbone. A lot of validation in common, 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 frontend, why not using Backbone.js models for the backend as well, so that there would be less code duplication ? I couldn't find info about that ... any pointers ? Is it a bad idea and why ? I can only guess that in that case you'd have to write your Backbone.sync
for database persistence.
EDIT
Practical issues that need to be solved to achieve that :
Backbone.sync
to work with mongodb (or whatever database is used).Upvotes: 4
Views: 1206
Reputation: 7802
After trying out for a while building the backend with Backbone
, I found it was total overkill, and brought more problems than simplifications. Instead I rolled back to using simple wrappers around mongodb
.
My initial thought in using Backbone was sharing url generation and model validation between backend and frontend. But as a matter of fact you don't need Backbone for that.
So I wrote reusable functions for validation and url generation, and used browserify
to make them available client-side.
Of course this might all change in the future if more people build tools for running Backbone backend-side ... but at the time of the writing, Backbone is definitely not made for that, and there's no library to help adapt it.
Upvotes: 1
Reputation: 10346
A bit outdated, but interesting nevertheless: Re-using Backbone.js Models on the server with Node.js and Socket.io to build real-time apps
A library to replace the default Backbone.sync by persisting to couchDB, when using Backbone on node.js: node-backbone-couch
Upvotes: 0