dirt

0.0.3 • Public • Published

dirt

Build Status

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'

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i dirt

    Weekly Downloads

    1

    Version

    0.0.3

    License

    ISC

    Last publish

    Collaborators

    • jpstevens