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'

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    1
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i dirt

Weekly Downloads

1

Version

0.0.3

License

ISC

Last publish

Collaborators

  • jpstevens