Configurable middleware refers to functions that can be customized, meaning there are variables that are not hardcoded and can be passed as parameters to those functions.
Some of the most widely used configurable components are the static
and the session
middleware. For the first one, we can configure the path for the static resources along with some more advanced features, while the session middleware can accept parameters such as secret
, key
, and other settings, as shown in the following code:
var session = require('express-session'); app.use(express.static('/public')); app.use(session({ secret: 'random chars', key: 'session_id', cookie: { secure: true } }));