From the course: Building a Website with Node.js and Express.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Express middleware and routes

Express middleware and routes

From the course: Building a Website with Node.js and Express.js

Start my 1-month free trial

Express middleware and routes

- [Instructor] Middlewares are key concepts of Express. Basically everything is built around them. We already created routing middlewares that will be executed when a specific URL matches, and to end a request for sending data back to the browser. We also used the Express static middleware to support static files like style sheets or images. And additionally to using existing middlewares, we can of course also define our own ones. Let's now dive into this topic a bit deeper. First, let's look at the overt syntax. Middlewares are defined on the application object and, in general, they use application dot use. And they take a callback. This is what will be executed for this given middleware, and the callback gets a request and a responsive check, but we will see that in a bit. We can also have a path as first argument to this app.use, this means the middleware will then be only executed if the URL matches a specific path.…

Contents