x-root-path

0.0.2 • Public • Published

x-root-path

A helper to help you find the project root directory

In our node project, we may need require many modules in a file, and we will find many ../ in the file. Now you can use the x-root-path module to solve the problem.

Install

npm install x-root-path

Use in project

Example:

There is some files in a project:

// Files:
// Project/lib/lib1.js
// Project/module/m1.js
// Project/view/test/test1.js

The test1.js is like this:

var lib1 = require('../../../lib/lib1');
var m1 = require('../../../module/m1');

// do something

We will find there is too many '../' in the test1.js file. But we can solve the problem after we use the x-root-path module.

Now we can write test1.js like this:

var ROOT_PATH = require('x-root-path');

var lib1 = require( ROOT_PATH + '/lib/lib1' );
var m1 = require( ROOT_PATH + '/module/m1' );

// do something

License

MIT

Package Sidebar

Install

npm i x-root-path

Weekly Downloads

2

Version

0.0.2

License

MIT

Last publish

Collaborators

  • walkerbe