Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications. It facilitates the rapid development of Node based Web applications. It has been written on top of Node’s HTTP module. It makes writing REST(representational state transfer) API easy and with minimum lines of codes.
Following are some of the core features of Express framework −
Allows to set up middlewares to respond to HTTP Requests.
Defines a routing table which is used to perform different actions based on HTTP Method and URL.
Allows to dynamically render HTML Pages based on passing arguments to templates.
From the perspective of concepts related to REST, we have GET, POST, PUT and DELETE type of requests over HTTP protocol.
GET - This is used to provide a read only access to a resource.
PUT - This is used to create a new resource.
DELETE - This is used to remove a resource.
POST - This is used to update a existing resource or create a new resource.
To get started we just need to install express framework in our application.
npm install --save express // --save flag is to save the entry in our package.json.
An example, which justifies everything that why its used. It’s simple and self explanatory.
var express = require('express');
In the similar fashion, we can have PUT and DELETE requests also written using Express framwework.
On a differnt Note: We often use Nodemon in Node, to allow our server to reflect changes as soon as it is done. Along with Nodemon, we often use JOI for validation. Joi is maintained by Hapi.js project. Even though hapi.js is a web framework by itself, Joi is independent and can be used in any type of node project. This is great for people using express or restify.
What makes it even more interesting is that, besides user validation, it can be used to define database schemas as well