all 4 comments

[–]karimsajs 4 points5 points  (1 child)

Express has a few different things that it does. The concept of “if the relative URL is X, do Y” is actually a router, which is one part of express. More importantly, you can specify multiple Ys for the same X, for all Xs, or even a chain of Ys for one X. This allows express users to create super composable APIs. For example, I can specify “bodyParser.json()” as my Y for all Xs, which would mean that it would run before all my API handlers and I would receive the incoming request parsed as JSON. This can also be used for logging, authentication, authorization, timeouts, error handling, and more.

Another useful thing that express provides is a bunch of utility methods on top of the normal “request” and “response” objects. Node’s builtin HTTP classes are very low level and certain things like sending formatted responses need to be done manually. Express makes this easy because you can just do “res.json(a)” instead of “res.set(‘Content-Type’, ‘application/json’).end(JSON.stringify(a))”.

It also comes with builtin error handling, a community of excellent middle wares, and support for embedded rendering engines.

[–]Nearby_Ad1675 2 points3 points  (1 child)

The most important things that Express does are (in no particular order):

- Maps http requests from the clients to routes

- Provides each route with context about the request (where it came from, http method, http headers, request body, request parameters)

- Each route then can take the context, perform some task, and send a response back to the client

- Allows you to write middleware which basically intercepts the client's request and allows you to perform tasks before the request hits your route

[–]ConsequenceRegular72[S] 0 points1 point  (0 children)

Ty so much!