Requirejs is currently one of the best ways to work with AMD modules both 
on browser and in node.js. Requirejs "wrap" plugin is nice for wrapping 
browser modules that don't support AMD. You can use in the browser without 
a build step (so that is nice for making source change and just hitting 
refresh) and then when you are ready for deploy, it can bundle things up 
and minimize.

Also for small projects that you want them to work both in AMD and non-AMD, 
you can use some boilerplate like these examples in UMD (universal module 
definition) https://github.com/umdjs/umd, specifically 
https://github.com/umdjs/umd/blob/master/returnExports.js which is one that 
works in all places. If you wrap your code with this, then it will work in 
all places without adding any dependencies.

I use mocha with chai to be able to support browser and node.js testing.

I believe there are still things that can be done to improve sharing, but 
these are a good start.


On Saturday, 2 June 2012 11:26:55 UTC-5, 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