Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Is it possible to make JavaScript module compatible with both NodeJS and RequireJS?

Is it possible to make JavaScript module compatible with both NodeJS and RequireJS?

Problem

I have been investigating how various Module concepts can be applied within Nodejs and browser applications using the the NodeJS require (obviously in NodeJS apps) and RequireJS for the web browser environment.

It then dawned on me that some modules may be useful for use by both the client and server applications and thus could be reused.

How can modules be developed so that they are compatible with both of these environments?

One is synchronous and one asynchronous. My first thought was to utilise the asynchronous syntax and then to define a custom module for NodeJS which simply invokes the asynchronous callback, synchronously. But how would the RequireJS-emulator be included into the cross-environment module without first using the NodeJS synchronous callback?

Problem courtesy of: Lea Hayes

Solution

See this post : Bridging the module gap between Node.js and browsers

Solution courtesy of: pradeek

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Is it possible to make JavaScript module compatible with both NodeJS and RequireJS?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×