Fwd: [nodejs] Best practices for sharing code and data between the server and client

7 views
Skip to first unread message

Amjad

unread,
Jun 2, 2012, 11:49:28 AM6/2/12
to microcommunity
This post is about YUI.

---------- Forwarded message ----------
From: Martin Cooper <mfnc...@gmail.com>
Date: Sat, Jun 2, 2012 at 6:45 PM
Subject: Re: [nodejs] Best practices for sharing code and data between the server and client
To: nod...@googlegroups.com


On Sat, Jun 2, 2012 at 6:20 AM, Amjad <iss...@gmail.com> wrote:
> Thank you very much everybody for your notes!
>
> @Martin
> I tried to have a fast look at YUI. What gives YUI the ability to run client
> code on the server? I mean what makes it different from other Javascript
> "MVC" frameworks such as Backbone.js?

A couple of quick examples:

* You specify your modules' dependencies declaratively, which means
that YUI can use the appropriate mechanism to load them, depending on
whether your code is running in the browser (and either static- or
lazy-loading) or on the server. It's transparent to you.

* With YUI, you would write your XHR / XDR code using the YUI.io API.
When that code is running on Node.js, YUI provides a different
transport behind the same YUI.io API, such that your code works
transparently.

* When you're working with the DOM, you use YUI's (very thin) Node
abstraction. This is the browser DOM in a browser, and jsdom on the
server, so that your DOM manipulation code continues to work in either
place.

Dav Glass has done a few presentations around how all this works. If
you're at all interested, I'd encourage you to watch at least one.
Dav's an entertaining presenter, and his demos are always fun.

http://www.yuiblog.com/blog/2010/04/05/running-yui-3-server-side-with-node-js/
http://www.yuiblog.com/blog/2010/04/09/node-js-yui-3-dom-manipulation-oh-my/
http://www.yuiblog.com/blog/2011/11/07/rocking-yui-on-node-js-and-mobile/

--
Martin Cooper


> On Thu, May 31, 2012 at 6:43 AM, Martin Cooper <mfnc...@gmail.com> wrote:
>>
>> On Wed, May 30, 2012 at 4:58 AM, Amjad <iss...@gmail.com> 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.
>>
>> That's in part because it rather depends on what you're trying to do.
>> For example, you might be:
>>
>> * trying to take existing code written for Node and run it in the browser
>> * trying to take existing code written for the browser and run it in Node
>> * trying to write a new codebase that will run in both places
>>
>> As has been mentioned, browserify is probably the best solution for
>> the first of these. I think it's safe to say that it garners the most
>> attention, in part because it's good at what it does.
>>
>> For the last case, you might want to take a look at YUI, which
>> provides the abstractions to let you write your code once and run it
>> in both places. Yahoo! has built Mojito on top of YUI and is using
>> that to create multi-device apps that transparently share code between
>> client and server. (BTW, you'll likely find that YUI is much more
>> lightweight and modular than you think.)
>>
>> --
>> Martin Cooper
>>
>>
>> > 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 nod...@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > nodejs+un...@googlegroups.com
>> > For more options, visit this group at
>> > http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>> --
>> 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 nod...@googlegroups.com
>> To unsubscribe from this group, send email to
>> nodejs+un...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>
>
> --
> 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 nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

--
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 nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply all
Reply to author
Forward
0 new messages