I have a Node.js app with following structure:
+
|-- app/
| |-- config.js
| |-- modules/ // MVC app modules/components.
| |-- login/
| |-- signup/
|-- lib/ // App specific modules/libraries.
| |-- auth/
| |-- storage/
|-- node_modules/ // 3rd party modules.
| |-- express/
| |-- hjs/
|-- public/
|-- app.js
|-- package.json
What are the options to require modules from lib/ inside - for example - the login module, but without having to specify the relative path?
// app/modules/login/index.js
var auth = require('../../../lib/auth'); // <-- I'd rather have require('auth')
module.exports = function(app) {
app.get('/', auth.ensureAuthenticated, function(req, res) {
res.send('/');
});
};
I do not want to host modules in lib/ on Github and would like to keep the *node_modules* directory for 3rd party modules only.
Modular web applications with Node.js and Express (see 2:25) by TJ looks very promising when he talks about bundledDependencies. But that doesn't seem to work yet.
Update:
I've now flattened my structure a little and decided to embrace relative paths instead.
I can see two possible solutions here.
npm install ./lib/storage
You can install your modules "dynamically" when you start your app.js by executing the previous command.