In this tutorial, you will learn how to setup a complete Node.js development environment, including NPM (the Node Package Manager) and Cloud9 IDE to edit, run, and debug Node programs. The following installation instructions have been sucessfully tested on Debian 6.0 “Squeeze” and on Ubuntu 12.04 “Precise Pangolin”, but they should also work properly on previous versions as well.
We will install everything in the user’s home directory : this way, there is no need for any root access to the machine (provided the required packages are, of course, already installed), and each user can manage its own version of Node.
We start by installing (as root) required packages to build Node and later fetch NPM and Cloud9 :
apt-get install build-essential g++ libssl-dev curl git
We create a ‘local’ directory within our home directory, and modify our .bashrc file to add it permanently to the $PATH variable :
mkdir ~/local echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc source ~/.bashrc
We fetch, unpack, configure, compile, and install Node. The latest stable version is currently 0.6.18, so we simply set the temporary $NODE_VERSION variable accordingly :
export NODE_VERSION='0.6.18' wget http://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION.tar.gz tar xvfz node-v$NODE_VERSION.tar.gz cd node-v$NODE_VERSION ./configure --prefix=~/local make install cd ~
We fetch and install NPM :
curl http://npmjs.org/install.sh | sh
We then install Sourcemint for NPM :
npm install -g sm
And finally, we fetch Cloud9 IDE and install it :
sm clone --dev https://github.com/ajaxorg/cloud9/tree/master cloud9
If everything went fine, congratulations, you can now launch Cloud9 IDE and type your first program. First launch can take some time, as the shellscript will need to get some required dependencies prior to run the program.
Note that the Cloud9 launcher accepts parameters allowing to specify IP and port to listen on, workspace directory, and so on and so far. Below is a list of all available options :
Show this help message --help Load the configuration from a config file. Overrides command-line options. Default:
-c, --config Run child processes with a specific group. Default: -g, --group Run child processes as a specific user. Default: -u, --user Activate debug-mode. Default: -d, --debug Define an action to execute after the Cloud9 server is started. Default: -a, --action IP address where Cloud9 will serve from. Default: <127.0.0.1> -l, --ip Port number where Cloud9 will serve from. Default: <3000> -p, --port127.0.0.1> Path to the workspace that will be loaded in Cloud9 (may be relative or absolute). Default: <.> -w, --workspace3000>
Now, point your browser to the following URL : http://127.0.0.1:3000
var http = require('http');
Run it :
And check the result in your Web browser :
Congratulations, you just ran your first Node program : see how easy and straightforward it was?
You now have everything ready in order to start developing Node.js applications! Should you need any information or resources to get you started, you can find useful links in the NodeCloud directory.