Creating npm packages which extend the functionality of Express apps has become a major thing we've been doing. There are several approaches we can take, from messing with the Express object prototypes, to creating a function in which an express app is passed in. After trying the former, I'm now a fan of the latter.
Extending the Express object prototypes has issues. The running Node.js process may have multiple versions of express
, and in order to extend the prototypes you need to require('express')
. This means that you might get a different express
module instance than the one the main app is created from.
Both approaches suffer from extending something more than once. Similar to how there may be multiple version of express
in the running Node.js process, there can also be multiple copies of the extension modules. If the app developer needs to rely on a different version of an Express ext