Popular libraries - CoffeeScript in Action (2014)

CoffeeScript in Action (2014)

Appendix C. Popular libraries

While learning to program in CoffeeScript, it’s important to deal only in language concepts and to build up programs using only the raw building blocks of the language instead of leaning too heavily on specific libraries or frameworks. Having said that, once you have learned CoffeeScript, there are many occasions when it makes sense to reach for a well-known and supported library or framework that takes an approach similar to your own.

What follows is a list of useful libraries and relevant websites for learning about them. In some cases the libraries are not only useful in your CoffeeScript programs but are themselves written in CoffeeScript—those libraries are indicated here.

npm

Although you’ve had experience with npm (the package manager that comes with Node.js), there are many aspects of it (such as dependency management) that you haven’t explored. Find out more about npm at http://npmjs.org/.

Testing

In chapter 10 you built up your own small testing framework. There are several excellent frameworks that can help to extend your testing prowess:

· Jasmine— Jasmine is the most popular testing framework for browser-based programs. Find out more at http://pivotal.github.io/jasmine/.

· Mocha— Mocha is one of the most popular testing frameworks for Node.js programs. Find out more at http://visionmedia.github.io/mocha/ or npm install mocha.

· Chai— Chai provides assertion matchers to help make your tests more readable. Find out more at http://chaijs.com/ or npm install chai.

· Zombie— Zombie provides a virtual browser (a mock browser) that you can use inside Node.js. Find out more at http://zombie.labnotes.org/ or npm install zombie. Zombie is written in CoffeeScript.

Modules

In chapter 12 you created your own support for Node.js module syntax in your browser-based program. There are a few alternatives to look at while you wait for JavaScript runtimes to support some native module system:

· Stitch— Stitch uses a setup similar to the one you built in chapter 12. Find out more at https://github.com/sstephenson/stitch or npm install stitch. Stitch is written in CoffeeScript.

· Browserify— Browserify provides a compiler to support Node.js modules. Find out more at http://browserify.org/ or npm install gamma.

· Bower— Bower provides a complete package system for your browser-based programs, similar to some of the features that npm provides on Node.js. Find out more at http://bower.io/.

Builds

In chapter 12 you used Cake to build your program. Although useful, Cake can be overly minimal for some needs:

· Make— Make is not specific to CoffeeScript, JavaScript, or Node.js, but it’s one of the most widely used build automation tools. Although Make can be intimidating to novices, it’s an important and effective tool that you should learn to use. Find out more athttp://www.gnu.org/software/make/.

· Grunt— Grunt is a task runner that runs on Node.js. Find out more at http://gruntjs.com/.

· Lineman— Lineman builds on top of Grunt and is targeted at build automation for browser-based programs. Grunt is a task runner that runs on Node.js. Find out more at http://linemanjs.com/. Lineman is written in CoffeeScript.

Deployment

In chapter 12 you looked briefly at deploying your CoffeeScript program to a server with SCP. There are alternatives. DPLOY is a configuration-driven SCP deployment tool for your Node.js program. Find out more at http://leanmeanfightingmachine.github.io/dploy/.

Instead of deploying to a server where you configure the environment, you might find it easier to deploy your application to a host that manages the servers for you. The two most popular options for Node.js are Heroku (http://www.heroku.com) and Nodejitsu (http://nodejitsu.com/). To make the most of these, you’ll need to be familiar with npm.

Frameworks

There are many competing web frameworks for Node.js, but the most popular is Express (http://expressjs.com/). The creator of Express has now also created a new framework based on generators called Koa (http://koajs.com/).

There are even more frameworks for browsers than there are for Node.js, but the ones you’ll find most interesting are Backbone.js (http://backbonejs.org/) created by CoffeeScript creator Jeremy Ashkenas and batman.js (http://batmanjs.org/), which is written in CoffeeScript.

Asynchronous programming

In chapter 9 you learned techniques for dealing with asynchronous programs. The most interesting development in this area is generator support in ECMAScript 6. But another interesting library to look at is bacon.js (https://github.com/baconjs/bacon.js), which uses functional reactive programming to move your event-driven code away from imperative and toward functional. Bacon.js is written in CoffeeScript.

Physical computing

Cylon.js is a framework for physical computing with Node.js. It has hardware support for many popular platforms including Arduino and Raspberry Pi. Find out more at http://cylonjs.com/ or npm install cylon. Cylon.js is written in CoffeeScript.

On GitHub

The popular web-based hosting service for projects that use Git is a good place to explore interesting new CoffeeScript programs. See popular recent programs written in CoffeeScript at https://github.com/trending?l=coffeescript&since=monthly.

Finally, be sure to keep track of the official CoffeeScript website at http://coffeescript.org, the CoffeeScript wiki at https://github.com/jashkenas/coffee-script/wiki, and the source code for CoffeeScript in Action at https://github.com/boundvariable/coffeescript-in-action.