Introduction to Express JS


                             Express JS

Express is a quick, un-opinionated, moderate Node.js framework intended for building APIs, web applications and cross-platform mobile applications. Presented by TJ Holowaychuk in 2010 and propelled by Sinatra software, Express is a lightweight framework with complete in-assembled application features.

 Express.js is a standard server for Node.js and back-end parts of the MEAN stack.

Express JS Manages:

  1. Routing
  2. Session
  3. HTTP Requests
  4. Error Handling

It removes the development time of the developers and helps in conveying effective and fast applications. Express is anything but easy to modify and configure and can be easily associated with the database like MongoDB, Redis, MySQL. As Express.js is written in JavaScript, it is an exceptionally simple language to learn and manipulate.


Why Should us Use Express JS

  • Ultra-fast I/O
  • Asynchronous and single-threaded
  • MVC like structure
  • Robust API for easy routing
  • High Performance

How Express JS Works

Express permits developers to listen in for HTTP requests on an assigned port. In my work, I frequently test a project with port 3000, 3001, and so on. The developer indicates how to deal with specific HTTP methods (GET, POST, PUT, DELETE) alongside the relating path of the request. This system ought to be familiar to any individual who has utilized React with React Router, which likewise characterizes certain responses to coordinate client requests.

Installing Express

Right off the bat, install the Express framework globally utilizing npm with the goal that it very well may be utilized to make a web application utilizing node terminal.


The above command saves the installation locally in the node_modules directory and makes a directory express inside node_modules. You ought to install the accompanying significant modules alongside express −
  • body-parser − This is a node.js middleware for taking care of JSON, Raw, Text, and URL encoded structure data. 
  • treat parser −  Parse Cookie header and populate req.cookies with an object keyed by the cookie names. 
  • multer −          This is a node.js middleware for taking care of multi-part/structure-data.


Features of Express JS    

  • Robust Routing 
  • Concentrate on high performance 
  • Super-high test inclusion 
  • HTTP helpers (redirection, caching, etc.) 
  • View framework supporting 14+ template engines 
  • Content arrangement 
  • Executable for creating applications quickly        

                                  Request and Response 

Express application utilizes a callback function whose parameters are request and response objects. 


  • Request − The request object speaks to the HTTP request and has properties for the request query string, parameters, body, HTTP headers, etc. 
  • Response − The response object speaks to the HTTP response that an Express application sends when it gets an HTTP request.      
Anyone can print req and res objects which give a lot of data identified with HTTP requests and responses including cookies, sessions, URLs, and so on.


Basic Routing

We have seen a fundamental application that serves HTTP requests for the landing page. Routing refers to deciding how an application responds to a client request to a specific endpoint, which is a URI (or way) and a particular HTTP request method (GET, POST, etc).

Serving Static Files

Express gives a build-in middleware express.static to serve static records, for example, pictures, CSS, JavaScript, and so forth. We basically need to pass the name of the registry where we keep our static resources, to the express. static middleware to begin serving the records straightforwardly.


                 

Comments

Popular posts from this blog

What is Application Framework

What REST Services Are

Application Framework Project