Using Express.js to Create Node.js Web Apps

  • Mardan A
N/ACitations
Citations of this article
34Readers
Mendeley users who have this article in their library.
Get full text

Abstract

Express.js is a web framework based on the core Node.js http module and Connect (http://www.senchalabs.org/connect) components. The components are called middleware and they are the cornerstones of the framework philosophy, which is configuration over convention. In other words, Express.js systems are highly configurable, which allows developers to freely pick whatever libraries they need for a particular project. For these reasons, the Express.js framework leads to flexibility and high customization in the development of web applications. If you write serious Node web apps using only core Node.js modules (refer to the following snippet for an example), you most likely find yourself reinventing the wheel by writing the same code continually over and over for similar boring mundane tasks, such as the following: • Parsing of HTTP request bodies Parsing of cookies • Getting information from URL • Reading query string data from URLs or request bodies (payloads) Managing web sessions • Organizing routes with a chain of if conditions based on URL paths and HTTP methods of the requests • Determining proper response headers based on data types The list could go on and on, but a good example is worth hundreds of words. To illustrate my point, here is an example of a two-route representational state transfer (REST) API server, i.e., we have only two endpoints and they are also called routes. In this application, we use only core Node.js modules for server functions. A single "userland"/ external module native MongoDB driver is used for persistence. This example is taken from my another best selling book on Node, beginner-friendly Full Stack JavaScript, 2nd Edition (https://github.com/azat-co/fullstack-javascript) (Apress, 2018). Pay attention to how I had to use if/else and parse the incoming data. const http = require('http') const util = require('util') const querystring = require('querystring') const mongo = require('mongodb') Chapter 2 Using express.js to Create node.js Web apps

Cite

CITATION STYLE

APA

Mardan, A. (2018). Using Express.js to Create Node.js Web Apps. In Practical Node.js (pp. 51–87). Apress. https://doi.org/10.1007/978-1-4842-3039-8_2

Register to see more suggestions

Mendeley helps you to discover research relevant for your work.

Already have an account?

Save time finding and organizing research with Mendeley

Sign up for free