CoffeeScript Application Development
上QQ阅读APP看书,第一时间看更新

Testing our Node installation

Let's make sure your Node installation is working properly. Check the version number with node -v. We will be shown a version number, as follows:

node -v
v0.8.15

Now let's open up the Node console. This is an interactive tool that lets you run JavaScript right from your command line! It can be very helpful if you want to try out small ideas in code and receive immediate feedback. We'll see later that CoffeeScript provides an equivalent console.

Run this:

node

You will be presented with a prompt. Try entering some JavaScript code, and hit Enter to execute.

> "Hello, world!"
'Hello, world!'
> var x = 3 + 7
undefined
> x / 2
5

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Testing npm

We'll also check if npm is installed. npm is the Node package manager. It is a set of utilities for installing and managing tools and libraries written for Node. It is backed by https://npmjs.org/, the official online repository for Node packages. Almost any public code written for Node will be published in the repository and can be installed seamlessly with a single npm command.

If you have version 0.6.3 or above of Node, it comes with npm automatically. If you are still in the Node console, hit Ctrl + D to close it and return to your regular command line.

npm -v

If you see a version number, you have npm and can continue on to the next step.

Tip

If you don't have npm installed, the best way to get it is to upgrade to a recent version of Node following the instructions stated earlier. If you really cannot upgrade your version of Node, follow the installation instructions at https://github.com/isaacs/npm/.