Shoshy,

thanks for your kind feedback. Yes you can just move any javascript file to 
the shared/js folder and adjust the file to require amdefine at the top 
(like in the example entry_validation file).
Then make sure to use the correct (relative) path on the client and server. 
Take a look at client/js/entry.js and server/models/entry.js
If you are using a Backbone.Model do not forget to require backbone on your 
server.

Regarding your SQL question: I do not have a solution for you. After 
experimenting a little bit with MySQL using http://www.sequelizejs.com/ 
(works with MySQL and Postgresql) and https://npmjs.org/package/mysql my 
code quickly turned into deep callback nesting. Especially when dealing 
with relationships. This made me think about that maybe NoSQL is a better 
fit for the Nodejs style, but I am still experimenting and looking for the 
opinion of other people.

On a side note if your are using a serverside ORM framework like 
Sequelizejs which has its own Model-Class/Syntax you cannot use the same 
model on the server and client because Backbone models are created by 
extending Backbone.Model and Sequelize models by using sequelize.define. 
Thats why I was going to just share the validation logic.
  
Nils

On Friday, August 10, 2012 10:38:29 PM UTC+2, shoshy wrote:
>
>
> Nils ,
>
> Thanks so much for your boilerplate, i'm new to node.js but i've been 
> working with backbone, we have the same boilerplate structure and bits of 
> code for that matter. 
> My question is , i need to share the SAME model of the client. Rather it's 
> for extending it or use it as-is. Does that mean that i can just put the 
> models directory from the client in the shared and use it from backbone as 
> is? 
>
> Also what is your suggestion for generalised SQL driver for node? (lets 
> say i want to connect to mysql OR to postreSQL but i don't want 2 . Like 
> PDO in php)
>
> Thanks again! would love to keep in touch. I'm adopting your boilerplate. 
> P.S. it needs updating (express changed their commands a bit)
>
> Shoshy
>
>
> On Saturday, June 2, 2012 7:26:55 PM UTC+3, Nils Lattek wrote:
>>
>> I found it a little difficult to setup a module sharing solution, because 
>> of the two different module formats (AMD and CommonJS). Projects such 
>> as browserify are awesome, but I wanted to try it with AMD modules.
>>
>> So after a lot of googling and experimenting I created a small demo 
>> project which shows how to share code between backbonejs and nodejs.
>> I do not use it to share the complete model, because most db-modules 
>> (like sequelizejs or mongoose) in node have their own way of defining 
>> models. So you would have to merge the definition code of a backbone model 
>> with the one of a mongoose model.
>> What I tried to do is share the validation logic between the client and 
>> the server. This kind of code can be executed regardless of which model 
>> format (backbone, mongoose, sequelize) you are using.
>> You could also use it for other kind of modules or to share 
>> Constants/enums across the client and server.
>>
>> The example also shows how to setup mochajs unittesting for these modules.
>> There are still some things which could be solved better and I am 
>> interested in seeing more examples from other people.
>>
>> You can find it here:
>> https://github.com/NilsLattek/backbone-requirejs-node-boilerplate
>>
>>
>> On Wednesday, May 30, 2012 1:58:46 PM UTC+2, al-Amjad Tawfiq Isstaif 
>> wrote:
>>>
>>> Hello everybody!
>>>
>>> I'm new to the great world of Node.js and have been playing around with 
>>> different modules and frameworks. However, there seems a lot of methods for 
>>> sharing server code with the client, and there are no default way for doing 
>>> that.
>>>
>>> I have come across many ideas:
>>>
>>> express-expose: this is a nice replacement for parsing JSON objects 
>>> rendered by the the server.
>>> https://github.com/visionmedia/express-expose
>>>
>>> This article exposes a hack to share backbone models on the Node server, 
>>> and they are trying to neat their hack with their Capsule and Thoonk 
>>> frameworks:
>>>
>>> http://andyet.net/blog/2011/feb/15/re-using-backbonejs-models-on-the-server-with-node/
>>>
>>> Syncrhonizing Backbone model using socket.io
>>> https://github.com/scttnlsn/backbone.io
>>>
>>> DNode and RPC as a method to use server methods on the client and vice 
>>> versa
>>> https://github.com/substack/dnode
>>>
>>> I know I've mixed a lot of topics, I thought sharing my confusion would 
>>> help to get more clarification, especially that there are a lot of 
>>> production projects based on Node, andI think that the community certainly 
>>> have reached a good collection of concepts and tools for sharing code 
>>> between the server and client. I would be very grateful for sharing your 
>>> thoughts about that.
>>>
>>> Best regards,
>>>
>>> Amjad
>>>
>>> *
>>> *
>>>
>>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to