356 CHAPTER 8 Websites and services
FIGURE 8-7 nstalling express, which also installs its dependenciesI
Using Visual Studio 2012 Express for Web
You can use Visual Studio 2012 Express for Web as your editor and file manager for a Node. js
folder structure by opening Visual Studio 2012 Express for Web, clicking File, and choosing
Open Web Site. Select the HelloExpress folder and click Open. Visual Studio opens the folder
structure for your use. If you click the Save All button, you find that Visual Studio creates a
solution file (.sln) that contains the settings, so you can easily use the .sln file to reopen the
solution.
You can continue to use your favorite text editor to work with the Node.js files, and you
still must keep a command prompt window open to run the Node.js application.
Creating a Hello web application with express
You have now installed express, so create a web application. In the HelloExpress folder, create
an app.js file and add the following to the file.
var express = require('express');
var app = express();
This code sets a reference to the express package that you installed and then creates an
express application object and assigns it to the app variable. This object provides many time-
saving features rather than creating everything from the beginning in Node.js.
Express provides the ability to define routes by using app.Method() syntax, in which
Method is the HTTP method, or verb. The following code is added to the app.js file, which
defines a route that matches a request by using the GET method and relative URL of “/”. Upon
match, the code is programmed to deliver a Hello World message to the user.