Installing Express
Installing Express is pretty straightforward, especially if you have Node installed already. Even if you don't have Node installed, you need not worry, because I will show you how to install Express from scratch, and that includes installing Node.
If you are on a Windows or Mac machine, installing Node is very easy—just download the respective installer from http://nodejs.org/download/. On Linux machines, the installation process is a little more elaborate. I will show you how to install Node on an Ubuntu machine.
Note
For a relatively easier and cleaner installation of Node, you can use Node Version Manager (nvm). Besides installing Node, it will help you flexibly switch to any version of Node right on your machine. Read more about nvm at https://github.com/creationix/nvm.
Before we go about installing Node, let's make sure we have the required dependencies on the system by executing the following command:
$ sudo apt-get -y install build-essential g++ libssl-devpkg-config
With that, we are ready to start
installing Node. Let's get the source code from the Node download page located at http://nodejs.org/download/. At the time of writing, the source code was located at http://nodejs.org/dist/v0.10.7/node-v0.10.7.tar.gz. Let's download the source code archive to the /tmp
directory and install Node from there:
$ cd /tmp $ wget http://nodejs.org/dist/v0.10.7/node-v0.10.7.tar.gz $ tar zxvf node-v0.10.7.tar.gz $ cd node-v0.10.7 $ ./configure $ make $ sudo make install
If everything went fine, you have Node installed on your system now. Let's confirm it with a quick Node version check command:
$ node -v > v0.10.7
Congratulations! Let's go install Express now.
As I mentioned earlier, installing Express is very straightforward once you have Node installed on your system.
Express is a Node module, and like any other Node module, it is installed using the Node Package Manager (npm), which comes installed with Node by default. You will learn more about npm and Node modules in a later section.
Node modules come in two variants: local and global. Local modules are meant to be used in a specific project, and are available only for that particular project, while global modules are installed system-wide, and are almost always available as a command-line tool.
Express is meant to be installed as a global module, so that we can use its express
command-line tool to generate Express app skeletons quickly.
Note
Express is the web development framework. express
is the command-line tool to create Express app skeletons.
We specify the
-g
option in the
npm install
command to install Node modules as global modules. Here is the command to install Express:
$ sudo npm install express -g
That command will install the latest stable version of Express. In case, you want to install a specific version of Express, you can specify the version using the @
parameter in the module name. Here is an example of installing an older version of Express:
$ sudo npm install express@3.0.5 -g
After the installation process is complete, confirm you are able to execute the express
command, with a version check:
$ express –V > 3.2.6
Congrats! Your system is ready for Express development now.