Skip to content

Commit 4c931e9

Browse files
committed
Bumped version to 1.0.0 + updated docs
1 parent 8fd48b2 commit 4c931e9

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

README.md

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# App Root Path Module
22

3-
[![Build Status](https://travis-ci.org/inxilpro/node-app-root-path.svg)](https://travis-ci.org/inxilpro/node-app-root-path)
3+
[![Build Status](https://travis-ci.org/inxilpro/node-app-root-path.svg)](https://travis-ci.org/inxilpro/node-app-root-path) [![Dependency Status](https://david-dm.org/inxilpro/node-app-root-path.svg)](https://david-dm.org/inxilpro/node-app-root-path)
44

5-
This simple module helps you access your application's root path from anywhere in the application without resorting to `require("../../path")`.
5+
> **Please Note:** Due to the very limited scope of this module, I do not anticipate needing to make very many changes to it. Expect long stretches of zero updates—that does not mean that the module is outdated.
6+
7+
This simple module helps you access your application's root path from anywhere in the application without resorting to relative paths like `require("../../path")`.
68

79
## Installation
810

@@ -12,7 +14,7 @@ $ npm install app-root-path --save
1214

1315
## Usage
1416

15-
To simply access the app's root path:
17+
To simply access the app's root path, use the module as though it were a string:
1618

1719
``` js
1820
var appRoot = require('app-root-path');
@@ -26,7 +28,7 @@ var reqlib = require('app-root-path').require;
2628
var myModule = reqlib('/lib/my-module.js');
2729
```
2830

29-
It's a little hacky, but you can also put this method on your application's `global` object:
31+
It's a little hacky, but you can also put this method on your application's `global` object to use it everywhere in your project:
3032

3133
``` js
3234
// In app.js
@@ -42,25 +44,27 @@ Finally, you can also just resolve a module path:
4244
var myModulePath = require('app-root-path').resolve('/lib/my-module.js');
4345
```
4446

45-
You can also explicitly set the path, using the environmental variable `APP_ROOT_PATH` or by calling `require('app-root-path').setPath('/my/app/is/here')`
47+
You can explicitly set the path, using the environmental variable `APP_ROOT_PATH` or by calling `require('app-root-path').setPath('/my/app/is/here')`
48+
49+
## How It Works (under the hood)
4650

47-
## How It Works
51+
> No need to read this unless your curious—or you run into a (very unlikely) case where the module does not work as expected.
4852
4953
This module uses two different methods to determine the app's root path, depending on the circumstances.
5054

51-
### Method One (preferred)
55+
### Primary Method
5256

53-
If the module is located inside your project's directory, somewhere within the `node_modules` directory (whether directly, or inside a submodule), we just do:
57+
If the module is located inside your project's directory, somewhere within the `node_modules` directory (whether directly, or inside a submodule), we effectively do (the actual code takes cross-platform path names/etc into consideration):
5458

5559
``` js
5660
path.resolve(__dirname).split('/node_modules')[0];
5761
```
5862

59-
This will take a path like `/var/www/node_modules/submodule/node_modules/app-root-path` and return `/var/www`. In 99% of cases, this is just what you need.
63+
This will take a path like `/var/www/node_modules/submodule/node_modules/app-root-path` and return `/var/www`. In nearly all cases, this is just what you need.
6064

61-
### Method Two (for edge cases)
65+
### Secondary Method (for edge cases)
6266

63-
The node module loader will also look in a few other places for modules (for example, ones that you install globally with `npm install -g`). Theses can be in one of:
67+
The node module loader will also look in a few other places for modules (for example, ones that you install globally with `npm install -g`). These can be in one of:
6468

6569
- `$HOME/.node_modules`
6670
- `$HOME/.node_libraries`
@@ -74,10 +78,13 @@ In these cases, we fall back to an alternate trick:
7478
path.dirname(require.main.filename);
7579
```
7680

77-
When a file is run directly from Node, `require.main` is set to its `module`. `module.filename` refers to the filename of that module, so by fetching the directory name for that file, we at least get the directory of the file that was called directly. In some cases (process managers and test suites, for example) this doesn't actually give the correct directory, though, so this method is only used as a fallback.
81+
When a file is run directly from Node, `require.main` is set to that file's `module`. Each module has a `filename` property that refers to the filename of that module, so by fetching the directory name for that file, we at least get the directory of file passed to `node`. In some cases (process managers and test suites, for example) this doesn't actually give the correct directory, though, so this method is only used as a fallback.
7882

7983
## Change Log
8084

85+
### 1.0.0
86+
- No changes. Just updated the version to signify a locked API (see [semver](http://semver.org/)).
87+
8188
### 0.1.1
8289
- Added Windows support (and, theoretically, other operating systems that have a directory separator that's not "/")
8390

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "app-root-path",
3-
"version": "0.1.1",
3+
"version": "1.0.0",
44
"description": "Determine an app's root path from anywhere inside the app",
55
"main": "index.js",
66
"scripts": {
@@ -12,7 +12,15 @@
1212
},
1313
"keywords": [
1414
"root",
15-
"path"
15+
"path",
16+
"utility",
17+
"util",
18+
"node",
19+
"module",
20+
"modules",
21+
"node_modules",
22+
"require",
23+
"app"
1624
],
1725
"author": "Chris Morrell <http://cmorrell.com>",
1826
"license": "MIT",

0 commit comments

Comments
 (0)