dirt
When writing tests, or traversing nested projects, do you ever have require chains like this?
;
So many dots. Did I put enough? Oh wait, another error 'module not found' error.
Solution:
dirt;
Ahh, much better.
Directory traversal made easy
Installation
In your project directory, run the command:
npm install dirt --save
Then, include the module in your javascript file:
var dirt = require('dirt');
Usage
#require
When editing the file:
#$ /Users/example/Documents/my-project/tests/server/unit/controllers/example-spec.js
We can add a dirt.require
method to our file to require files higher up in the directory tree:
var example = dirt);
The about command will require the path:
#$ /Users/example/Documents/my-project/tests/server/unit/controllers/example-spec.js
#up
Many, many dots:
dirt;// returns '../../../..'
So many dots, attached to a file path:
dirt;// returns '../../../../server/controllers/example.js'