Express.js is a Javascript framework based on Node.js, that supports development both on the server side and the user side. Express is a very fast, essential, assertive, and moderate web framework of Node.js. You can assume express as a tier built on the top of the Node.js that helps in managing server and routes. It provides a robust set of features to develop a web application and mobile applications. It is lightweight Framework of node.js. Express provides a minimal interface to build our applications. It provides the tools that are required to build our app. It is flexible as there are numerous modules available on node package manager (npm), which can be directly plugged into Express.

Topics Covered

  • Feature of Express
  • How does Express work?
  • Why Express?

Features of Express Framework:

  •  Express can be used to design a single-page, multi-page and hybrid web applications.
  • Express allows to setup middlewares to respond to HTTP Requests.
  • Express defines a routing table which is used to performs different actions based on HTTP method and URL.
  • Express allows to dynamically render HTML Pages based on passing arguments to templates.

How does Express work?

Express applications work by sending a sequence of calls to the middle tier. The middleware has of two-course access to request objects and response objects. It means that using the Express framework gives you control over all request and response objects. This gives you the power to add the sessions, add the post parameters, and template through ejs.

Why Express?

  • Ultrafast Input/Output.
  • Asynchronous and single threaded.
  • MVC like structure.
  • Robust API makes routing very easy.

How does Express look like :

Let’s see a basic express.js Example-

express.js

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

app.get('/', function (req, res) {  
    res.send('Welcome to Pabbly.com!');  
});

var server = app.listen(8000, function () {  
    var host = server.address().address;  
    var port = server.address().port;  
    console.log('Example app listening at http://%s:%s', host, port);  
});

Result :

Welcome to Pabbly.com!

Learn More: