Take the 2-minute tour ×

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 =
    a: require('./twtmore/a.coffee').a
    b: require('./twtmore/b.coffee').b
    c: require('./twtmore/c.coffee').c


class a

exports.a = a
share|improve this question
Just because php supports running javascript doesn't mean it's a good idea to use that for a library. Likewise, if you want an event loop server that works for coffee script you need to find that server, not run another language ontop of JS. –  Incognito Apr 8 '12 at 23:15
I think you may have misunderstood my question. More relevant comments below... –  tarnfeld Apr 9 '12 at 19:58
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
Thanks for the concise answer. I simply wanted to use node for the require functionality and nothing more, by the looks of RequireJS it is aimed at requiring files when they are needed, I just want a clean and structured development environment that I can then compile into a single javascript file for production use. –  tarnfeld Apr 9 '12 at 19:41
Ah. Check out the RequireJS Build Optimizer. It does what you are looking for and can be run using either Node.js or Java. requirejs.org/docs/optimization.html –  Timothy Strimple Apr 9 '12 at 19:51
That looks awesome! Do you know any projects that are using this off the top of your head? Would be nice to see it out in the wild.. –  tarnfeld Apr 9 '12 at 19:55
You can see what NPM packages require it on the NPM website: search.npmjs.org/#/requirejs Otherwise, it may be worth taking a look at who has forked the requirejs code on GitHub. –  Timothy Strimple Apr 10 '12 at 3:15
add comment

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.


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
share|improve this answer
While I completely and thoroughly agree with you -- CoffeeScript is ridiculous -- I don't really think this answer is very constructive. –  josh3736 Apr 8 '12 at 23:14
@josh3736 it answers the direct question which is to use browserify to manage commonJS in the browser. And it gives a strict warning that writing open source libraries in CoffeeScript is highly frowned upon and counter productive to the community. People need to be educated. I'm mainly hammering about how compile to js languages are not suited for libraries and are better suited for closed source, rather then hammering on about how bad CoffeeScript is –  Raynos Apr 8 '12 at 23:19
Whether or not you like coffeescript is irrelevant, and a waste of time in this answer. The statement that "coffeescript is unreadable" can only be ignorant and quite frankly, stupid –  PandaWood Apr 9 '12 at 1:50
CoffeeScript isn't unreadable, it just requires a deep and high amount of learning to have a strong confidence over exactly what JavaScript is outputted from it. JavaScript developers cannot read CoffeeScript code, they are forced to waste their time learning CoffeeScript –  Raynos Apr 9 '12 at 10:45
Personally I think CS is perfectly readable and has plenty of handy features, however I agree it's not a good idea to fragment the community, especially if its going to be open source. –  tarnfeld Apr 9 '12 at 19:44
show 4 more comments

Your Answer


