Getting Started with Express
Express provides a robust set of features for building web applications. In the first chapter, we briefly talked about Express.js, and discussed its advantages and limitations. This topic is about the implementation of Express in an application.
Creating an Express application requires the following steps:
Importing the Express module
Creating the Express application
Defining the route
Listening to the server
Take a look at the following example in Express:
// load express module var express = require('express'); //Create express app var app = express(); // route definition app.get('/', function (req, res) { res.send('Hello World'); }); // Start server app.listen(4000, function () { console.log('App listening at Port 4000..'); });
In the preceding code snippet, the Express module is first loaded and assigned to a variable. Then, an app is created using the variable function. The app.get() method is used to define the route by passing in a route path and a callback...