dirt
v0.0.3
Published
Directory traversal made easy
Downloads
2
Maintainers
Readme
dirt
When writing tests, or traversing nested projects, do you ever have require chains like this?
require('../../../../lib/example.js');
So many dots. Did I put enough? Oh wait, another error 'module not found' error.
Solution:
dirt.require(4, 'lib/example.js');
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.require(4, 'server/controllers/example.js'));
The about command will require the path:
#$ /Users/example/Documents/my-project/tests/server/unit/controllers/example-spec.js
#up
Many, many dots:
dirt.up(4);
// returns '../../../..'
So many dots, attached to a file path:
dirt.up(4, 'server/controllers/example.js');
// returns '../../../../server/controllers/example.js'