354 CHAPTER 8 Websites and services
Uninstalling a package
Uninstall a local package by executing the following command from the root folder of the
application.
npm uninstall math_example
To uninstall a global package, execute the following command.
npm uninstall -g math_example
Fast forward to express
Although it is relatively easy to create a Hello module with Node.js, much more work is
necessary if you intend to create a complete web framework. For example, when a request is
received at the server for a resource such as a webpage or a web service, you typically need
to route the request to get the proper resource. You might also want to implement sessions
to hold data between each request. What about authentication? It doesn’t make sense for
you to create this framework when you can install a more streamlined framework. The express
web application framework for node.js is available at http://expressjs.com/. You can install
express by using the previously mentioned npm install command, or you can read the next
section to learn how to install express from a dependency list.
This framework is also referred to as expressjs or simply express. In this book, it will be
referred to as express. The express framework provides a thin layer of features over Node.js,
where performance is maintained.
Starting with express
To begin using express, you must install Node.js first, and then you create a folder for your
web application. In this example, the folder is the following.
C:\node_samples\HelloExpress
Next, you set up a dependency on express, so you need the current version number of
express. Execute the following command to get the version information.
npm info express version
At the time of this writing, the version is 3.0.0. You need this version number when you add
the dependency to the package.json file.
To create the package.json file in the HelloExpress folder, navigate to that folder, execute
the following command, and follow the prompts.
npm init
The following is the completed package.json.
{
"name": "HelloExpress",
Key
Te rms