Skip to content Skip to sidebar Skip to footer

Commonjs Modules - Exporting A Function That Returns A Function With Arguments

In this rendr - sessions example, there's an express middleware module... module.exports = function incrementCounter() { return function incrementCounter(req, res, next) { va

Solution 1:

rendr uses Express-style middleware.

By convention, third-party middleware in Express are not provided as the actual middleware. Instead, they are provided as functions that create the middleware based on an options object parameter.

However, since there are no options to be provided here, it is omitted.

But still, in order to follow the conventions of the surrounding library, it needs to be a factory function that returns a middleware function. So that's why it is wrapped up that way here.

Post a Comment for "Commonjs Modules - Exporting A Function That Returns A Function With Arguments"