Book Image

Express Web Application Development

By : Hage Yaaapa
Book Image

Express Web Application Development

By: Hage Yaaapa

Overview of this book

Express is a minimal and flexible node.js web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications. It provides a thin layer of features fundamental to any web application, without obscuring features that developers know and love in node.js. "Express Web Application Development" is a comprehensive guide for those looking to learn how to use the Express web framework for web application development. Starting with the initial setup of the Express web framework, "Express Web Application Development" helps you to understand the fundamentals of the framework. By the end of "Express Web Application Development", you will have acquired enough knowledge and skills to create production-ready Express apps. All of this is made possible by the incremental introduction of more advanced topics, starting from the very essentials. On the way to mastering Express for application development, we teach you the more advanced topics such as routes, views, middleware, forms, sessions, cookies and various other aspects of configuring an Express application. Jade; the recommended HTML template engine, and Stylus; the CSS pre-processor for Express, are covered in detail. Last, but definitely not least, Express Web Application Development also covers practices and setups that are required to make Express apps production-ready.
Table of Contents (15 chapters)
Express Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 [email protected] -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.