Book Image

CoffeeScript Application Development

By : Ian Greenleaf Young
Book Image

CoffeeScript Application Development

By: Ian Greenleaf Young

Overview of this book

JavaScript is becoming one of the key languages in web development. It is now more important than ever across a growing list of platforms. CoffeeScript puts the fun back into JavaScript programming with elegant syntax and powerful features. CoffeeScript Application Development will give you an in-depth look at the CoffeeScript language, all while building a working web application. Along the way, you'll see all the great features CoffeeScript has to offer, and learn how to use them to deal with real problems like sprawling codebases, incomplete data, and asynchronous web requests. Through the course of this book you will learn the CoffeeScript syntax and see it demonstrated with simple examples. As you go, you'll put your new skills into practice by building a web application, piece by piece. You'll start with standard language features such as loops, functions, and string manipulation. Then, we'll delve into advanced features like classes and inheritance. Learn advanced idioms to deal with common occurrences like external web requests, and hone your technique for development tasks like debugging and refactoring. CoffeeScript Application Development will teach you not only how to write CoffeeScript, but also how to build solid applications that run smoothly and are a pleasure to maintain.
Table of Contents (19 chapters)
CoffeeScript Application Development
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Using the installer


The Node project provides an install file for Windows systems. Visit http://nodejs.org/download/, and look for Windows Installer:

Download that file and double-click on it. Follow the prompts to install Node on your system.

Using the standalone executable

The Node project provides a node.exe file that you may download and call without installing anything on your system. Visit http://nodejs.org/download/, and look for Windows Binary.

Download that file and put it in a directory you'll remember. Now you can call the file from the command line using the full path, as follows:

"C:\Documents and Settings\Ian\Software\node" -v

To save yourself some typing, you'll probably want to add that directory to your path. Once you do that, you can just call node without the full path.

Tip

If you don't know how to add directories to your path, you can find instructions at http://www.computerhope.com/issues/ch000549.htm.

Using Chocolatey

Chocolatey is a package management system for Windows based on NuGet and Powershell. It is modeled on package managers for other systems, but is designed to deal with the Windows environment. It provides simple installation of many developer tools and libraries.

To install Node using Chocolatey, simply use the command-line installer:

cinst nodejs.install

Tip

For help with Chocolatey, visit the official site at http://chocolatey.org/.

Installing Node.js on Linux

The easiest way to install Node on Linux is to use the package manager for your particular distribution. Most distributions offer a Node package, which will save the trouble of building it manually. If your distribution does not offer a Node package, see the Compiling Node.js manually section at the end of this chapter.

Using a graphical package manager

If you have a graphical utility to manage your system, such as Ubuntu Software Center or Synaptic, you can use that. Open the program and search for "nodejs". You will see a result similar to the following screenshot. Choose Install and wait until it informs you that it is finished.

Using the command line

If you don't have a graphical utility, that's not a cause for alarm. Many distributions still use a command line tool to manage packages. Start by opening up a terminal. The exact commands to install Node depend on your package manager. Here are some of the more common options.

Tip

If you can't find your distribution listed here, try the Node.js wiki at https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager.

Linux Mint/Ubuntu 12.04 (Precise Pangolin)

Ubuntu, Mint, and other distributions based on Debian unstable can use the venerable apt-get command-line tool to install Node.

sudo apt-get install nodejs
Debian Sid/Ubuntu 12.10 (Quantal Quetzal)

Systems using cutting-edge Debian packages can install Node with apt-get as stated earlier. However, you may also want to install the nodejs-legacy package, which provides the node executable. If you do not install this extra package, you will need to invoke Node on the command line with nodejs instead of node (this change was introduced to deal with a conflict between two different packages that both provide a node executable).

sudo apt-get install nodejs nodejs-legacy
Arch Linux

Arch Linux offers an official Node package, which may be installed using the pacman command-line tool:

sudo pacman -S nodejs
Fedora

Node is available in Fedora 18 and later versions. Install it through the package manager:

sudo yum install npm

If you are using an older Fedora release, see the following section.

Compiling Node.js manually

If you cannot install Node using one of the methods listed earlier, you may be able to compile it from source. This will work on most UNIX-like systems (including Mac OSX, Linux, and BSD). You may need some perseverance—compiling software from source often involves a few hiccups along the way. Remember, if you get stuck, a search engine is your best friend.

Tip

For more information and solutions to some common problems, visit the Node wiki page on installation at https://github.com/joyent/node/wiki/Installation.

First let's install the dependencies we'll need to build Node. These include a C++ compiler, the make build tool, and Python (which is used in the build process).

sudo apt-get install python g++ make

Tip

The exact method you use to install the dependencies will vary based on your operating system. The commands shown should work for Debian based systems, including Ubuntu and Linux Mint. OS X users will need to install Xcode, and then install the Command Line Tools through Xcode.

Now we need to download the Node source code. Visit http://nodejs.org/download/ and choose Source Code. Save it to somewhere you can remember, say ~/Downloads.

Let's visit the directory where you saved the file and unpack it. Note that the filename will have a version number in it that may be different from what is printed on the screenshot and in the command-line instructions.

cd ~/Downloads
tar xzvf node-v0.8.15.tar.gz
cd node-v0.8.15/

Now we'll prepare, build, and install Node. Be patient—these commands can take a while to complete!

./configure
sudo make install

Tip

These commands may throw errors if they don't find everything they need on your system. Read the error messages carefully. If you can't figure it out on your own, try searching online with the text of the error messages. Often you will find an existing post with a solution to the problem you are encountering.

Skipping the Node installation step

On certain systems, it may be possible to install CoffeeScript as a system package, rather than installing Node first as we are doing. For example, older versions of Homebrew offered a coffeescript package, and Ubuntu provides a CoffeeScript package that can be installed through apt.

However, these packages may be buggy or out-of-date, and you may find it difficult to control which version of the CoffeeScript package you are using. You will be at the mercy of a package maintainer (who may not even be actively updating the package any more). I strongly encourage you to follow the process detailed in the earlier sections of this chapter . Once you have installed Node, it will be very easy to manage your CoffeeScript installation, and you'll be glad you took this route.