I often see Node.js applications with the following structure:
Common pattern:
lib/
or src/
- the self-written code
index.js
- main codenode_modules
package.json
What I don't like about this pattern:
I don't feel comfortable about it because you have to explicitly specify the directory path of the internal modules when require()
ing:
// /lib/index.js
var internalMod = require('./internal'); // `require('internal')` (without path) wouldn't work
internalMod.doSomething();
So I think it would be a good idea also to place internal modules in an node_modules
folder (somewhere in the project). So node
would be able to find them, even if you don't explicitly specify the path.
For example:
src/
- the self-written code
index.js
- main codenode-modules
- for internals
node_modules
- for externals
package.json
Thanks for your answer (or comment). - If anything is unclear, please comment.
Perhaps you could use npm link
to pull your modules into node_modules?
See: https://docs.npmjs.com/cli/link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With