7.Express RequestResponseCycle
Request-Response Cycle
The essence of express development is to understand and then use the request-response cycle
.
Express app receives a request when some one hits the server, then it creates a req object and res object. This data is then used and processed inorder to generate and send back a meaningful response.
In order to process the data, in express we use middleware, which can manipulate the request or response objects or execute any other code. We use middleware mostly for request processing.
Middleware is the function that executed in middle , that is in between receiving the request and sending the response.
In Express, everything is middleware(even route definitions)
Examples of middleware: parsing the body, logging, setting headers, router.
All the middleware we use in app is called middleware stack.
Order of the middleware in the stack is defined as the order of the code.
The request-response cycle starts with the incoming request, then executing all the middleware in middleware stack step by step and finally sending the response to finish the cycle.
Configuration of prettier with eslint
npm i eslint prettier eslint-config-prettier eslint-plugin-prettier eslint-config-airbnb eslint-plugin-node eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react --save-dev
eslint-plugin-airbnb eslint-plugin-node eslint-plugin-import eslint-plugin-jsx-ally eslint-plugin-react are for styling.