express-middleware-module-loader loads middleware as modules from a specified directory or directories and automatically registers them under the module path.
Middleware modules are to be loaded from the
hooks directory and get mapped to
<PROJECT DIR>/hooks/ <PROJECT DIR>/hooks/hook1 <PROJECT DIR>/hooks/hook2
Code in api.js:
var hooks = require('express-middleware-module-loader')('./hooks/'); ... app.use('/hooks', hooks);
hook1 would then become available as /hooks/hook1/*