On May 8, 5:05 am, Robert Chris Bang Larsen <[email protected]>
wrote:
> So, how would you go about having shared code between Node.js and the
> client side ?

If the code is standalone and doesn't need anything specific to node
or doesn't require other modules (although something like browserify
might help with that in that case), you can simply just do a check for
`module.exports` at the end of your script. If it exists, then add
your functions and whatnot to that so that it can be used as a module,
otherwise if `module.exports` is not defined, attach functions, etc.
to something like `window`.

That's generally how I've shared validation logic and other "plain
javascript" stuff.

-- 
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