Express.js, Middleware and Routes: a brief overview - mwilkin-401-advanced-javascript/bend-javascript-401d2 GitHub Wiki

Express is a flexible, unopinionated, server-side ¬web application framework that works on top of Node.js which allows quick creation of APIs by utilizing a number of HTTP utility methods and middleware.

Unopinionated frameworks have fewer restrictions on the best way to utilize components to achieve some goal, or even which components should be used. They make it easy to utilize whatever tools are most suitable to complete at task.

Opinionated frameworks have a particular or “right” way to handle a particular task. They are very good at handling problems within a domain because the solutions are well known and well documented, but offer fewer choices for which components and approaches for task solutions can be used.

What is Middleware? They are functions that have access to the request object (req), the Response object (res) and the next or downstream middleware function in the request-response cycle. They allow you take action on any incoming request and modify it before sending back a response.

The order of Middleware calls as they are written in the file, it the order in which they are executed.

Middleware functions will have the next key word included in the function parameters and also in the code block to ensure that as the request is being processed each successive middle function must complete before moving on to the next.

Middleware can be custom created to perform some function necessary to the application, or there is a large amount of third-party middleware that can be called on to fulfill specific purposes.

To execute common routines, routing is used. Routes all for specific actions to occur based on a path. Common options are GET (retrieve), POST (create), PUT (update) and DELETE (delete).

Router: lets you group the routes so that common rules can be created.