Whats the best way to use CoffeeScript and Node.js together when writing a javascript library?

I'm writing a javascript library and want to use the awesomeness that is CoffeeScript to keep the code clean while writing it, but i'd also like to use something like Node mainly for its require feature. The idea is to namespace my sub-objects under a global object, and each of the sub-objects defined in their own file for ease of development.

Maybe I am going about this the wrong way, I just need a clean way to write a client side javascript library with CoffeeScript?

Thanks! Example file structure below...

./twtmore.coffee

twtmore =
    a: require('./twtmore/a.coffee').a
    b: require('./twtmore/b.coffee').b
    c: require('./twtmore/c.coffee').c

./twtmore/a.coffee

class a
    ...

exports.a = a

Yes, you are going about this the wrong way. Node.js is a server side technology. What you are looking for is using something like RequireJS or CommonJS modules (which is what node uses) in coffee script on the browser.

There is a plugin for using CoffeeScript with RequireJS which seems to do what you want but I have not used it and cannot vouch for it.

CommonJS for the browser

As for using node.js to write a client-side JavaScript library, just use modul8 or browserify to compile it into a single JavaScript file.

CoffeeScript

If you value people using your library then No, don't do it.

The JavaScript community will hate you for publishing an open source javascript library who's source code is written in CoffeeScript

<aside> CoffeeScript is a horrible language </aside>

Seriously though

  • You will lose popularity because people outright refuse to use your code since its not javascript
  • People will not patch or read it because CoffeeScript is unreadable
  • you're fragmenting the community