The Express Platform

T

Express is a minimal and flexible platform that provides a set of features for easy and fast web application development:

1. It is integrated with different middle-ware to which it delegates HTTP requests and responses;

2. Defines a route system through which it determines what action is taken based on the resource that is requested and the method used;

3. Allows the generation of Internet pages based on templates to which various arguments are transmitted;

4. Provides access to information stored in different data sources.

The Express platform can be deployed globally to be used with Node.JS to develop web applications.

Installing NodeJs is quite simple:

1. Ubuntu, Mint by:

sudo apt-get install nodejs

2. Installing npm is just as simple through

sudo apt-get install npm

For those who do not know what npm is, this is a packete nodejs manager.

3. After installing the Node and NPM you need to install the Express framework. Generate a new application by:

sudo npm install -g express-generator

4. Create a new application by:

express /applocation

5. Install dependencies by:

npm install

6. Run the application by:

npm start

7. If you go to the browser and go to http://localhost:3000/ you’ll see the message: Express. Welcome to Express.

By using the -save option, the Express module is stored in the package.json file in the dependency list.

Other modules that need to be installed for use with Express are:
• body-Parser – Middleware for managing coded data in JSON format, binary, text or URL;
• cookie-Parser – Middleware to ensure persistence in a web application by using cookies;

The request.cookies object will contain a list of pairs (attribute, value) based on the information retrieved from the HTTP headers.
• Multer – Middleware for multipart/form-date resource processing.

A web application using the Express platform will perform the following operations:

1. Load the Express module and build an instance of it;
2. Specify the contexts that can be accessed as well as the methods by which they can be viewed in the browser, the get, post, put, options, trace, delete methods get as a path parameter and a callback function that has arguments demand and response;
3. It will launch the web application through a call to the listen method, which receives as parameter the port on which the application is accessible as well as a callback function invoked when the web application is running.

Access to static resources (images, style sheets, JavaScript source code) can be achieved through the express.static middleware that is integrated with the Express platform. Thus, the use method will receive as a parameter the result of the express.static function, to which will be transmitted as argument the location where the resources can be found. Those resources can be referenced directly from the navigator, since the reference is being made when the static directory is being named. The static directory will not be included in the URL when trying to retrieve that information.
If multiple directories containing static resources are used, they will be listed sequentially, which will also determine the search order when a specific request is resolved.

About the author

Ilias spiros
By Ilias spiros

Recent Posts

Archives

Categories