0.1.1 • Published 11 years ago
toplevel v0.1.1
Toplevel
Toplevel is a super simple node module that wraps the built-in require() and lets you require your code relative to a top level directory rather than relative to the current file.
How it works
Create an empty Top file in the top level directory of your code.
$ touch Toplevel
$ tree -I node_modules .
.
├── app.js
├── lib
│ └── example.js
├── package.json
├── test
│ └── example_test.js
└── Top
Now any code in subdirectories like lib or test can use topl to require modules relative to the Top file.
test/example_tests.js:
var requireFromTop = require('toplevel')(__dirname)
,example = requireFromTop('lib/example');
...