express How does ExpressJs work Handling request/response


The syntactic sugar

Most of the getting started examples of ExpressJs include this piece of code

var express = require('express');
var app = express();

Well, app.listen is just a shortcut for:

var express = require('express');
var app = express();
var http = require('http');

The Express App

The famous http.createServer accept a function which is known as the handler. The handler takes 2 parameters request and response as inputs, then manipulating them inside it's scope to do various things.

So basically app = express() is a function, taking place as the handler and dealing with request, response through a set of special components referred as middlewares.