By Will Laurance on 03/27/2019
Express is a fun and minimal Node.js web app framework. What is a framework exactly? In Node.js, there is an http library. This library can be used on its own to make a HTTP client and a HTTP server. Express uses the HTTP server functionality to make writing HTTP apps easier.
The first benefit I like to point out about express is route parsing. If you use the bare bones http server you have to do all of the route parsing using string parsing! Think complicated regular expressions, accidentally globing incorrectly, and un-handled responses.
Express router solves this problem with functions to represent the
first argument to the function is a string. In this string we can
provide simple variable markers. For example
postId available in the
req.params object. We'll get into
express routing in the express router example.
The second concept express js does well is middleware. Middleware is typically library code or your own middleware that reads and/or writes request data. A simple example is express request logging. A more complex example is middleware that looks at cookie data to authenticate that a user is logged in. PassportJs is a perfect example of complex authentication middleware for express. This middleware can be chained together to perform many tasks per requests with minimal code.
Are you ready to get started with this Express js tutorial?