{
  "name": "app-root-path",
  "description": "Determine an app's root path from anywhere inside the app",
  "main": "index.js",
  "browser": "browser-shim.js",
  "scripts": {
    "test": "nyc mocha -R spec",
    "report-coverage": "npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov",
    "release": "semantic-release pre && npm publish --tag next && semantic-release post"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/inxilpro/node-app-root-path.git"
  },
  "keywords": [
    "root",
    "path",
    "utility",
    "util",
    "node",
    "module",
    "modules",
    "node_modules",
    "require",
    "app"
  ],
  "author": {
    "name": "Chris Morrell",
    "email": "http://cmorrell.com"
  },
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/inxilpro/node-app-root-path/issues"
  },
  "homepage": "https://github.com/inxilpro/node-app-root-path",
  "devDependencies": {
    "codecov": "^1.0.1",
    "coveralls": "^2.11.2",
    "cracks": "^3.1.2",
    "cz-conventional-changelog": "^1.2.0",
    "ghooks": "^1.3.2",
    "istanbul": "^0.3.4",
    "mocha": "^2.0.1",
    "mocha-lcov-reporter": "0.0.1",
    "nyc": "^8.1.0",
    "semantic-release": "^4.3.5",
    "validate-commit-msg": "^2.8.0"
  },
  "release": {
    "branch": "development"
  },
  "config": {
    "ghooks": {
      "commit-msg": "validate-commit-msg",
      "post-merge": "npm install",
      "post-rewrite": "npm install"
    },
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  },
  "version": "1.4.0",
  "readme": "# App Root Path Module\n\n[![Build Status][build-status-img]][build-status] [![Dependency Status][david-dm-img]][david-dm] [![Code Coverage Status][codecov-img]][codecov]\n\n> **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.\n\nThis simple module helps you access your application's root path from anywhere in the application without resorting to relative paths like `require(\"../../path\")`.\n\n## Installation\n\n``` bash\n$ npm i -S app-root-path\n```\n\n## Usage\n\nTo simply access the app's root path, use the module as though it were a string:\n\n``` js\nvar appRoot = require('app-root-path');\nvar myModule = require(appRoot + '/lib/my-module.js');\n```\n\n> _Side note: the module actually returns an object, but that object implements the `toString` method, so you can use it as though it were a string.  There are a few edge cases where this might not be the case (most notably `console.log`), but they shouldn't affect actual use of the module, where you're almost always concatenating with an additional string._\n\nA helper function is also provided:\n\n``` js\nvar reqlib = require('app-root-path').require;\nvar myModule = reqlib('/lib/my-module.js');\n```\n\nIt's a little hacky, but you can also put this method on your application's `global` object to use it everywhere in your project:\n\n``` js\n// In app.js\nglobal.reqlib = require('app-root-path').require;\n\n// In lib/module/component/subcomponent.js\nvar myModule = reqlib('/lib/my-module.js');\n```\n\nFinally, you can also just resolve a module path:\n\n``` js\nvar myModulePath = require('app-root-path').resolve('/lib/my-module.js');\n```\n\nYou can explicitly set the path, using the environmental variable `APP_ROOT_PATH` or by calling `require('app-root-path').setPath('/my/app/is/here')`\n\n## How It Works (under the hood)\n\n> No need to read this unless your curious—or you run into a (very unlikely) case where the module does not work as expected.\n\nThis module uses two different methods to determine the app's root path, depending on the circumstances.\n\n### Primary Method\n\nIf 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):\n\n``` js\npath.resolve(__dirname).split('/node_modules')[0];\n```\n\nThis 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.\n\n### Secondary Method (for edge cases)\n\nThe 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: \n\n  - `$HOME/.node_modules`\n  - `$HOME/.node_libraries`\n  - `$PREFIX/lib/node`\n\nOr, anywhere in the `NODE_PATH` environmental variable ([see documentation](http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders)).\n\nIn these cases, we fall back to an alternate trick:\n\n``` js\npath.dirname(require.main.filename);\n```\n\nWhen 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.\n\n### Edge-Case: Global CLIs\n\nIf your module is installed as a global CLI, for example in `/usr/local/lib/node_modules/yourmodule`, then\n`require.main.filename` will report `/usr/local/lib/node_modules/yourmodule/bin`, which is probably not what\nyou want. `app-root-path` is aware of this edge-case and will strip the `/bin` automatically.\n\n## Change Log\n\n### 1.3.0\n  - Updated [electron](https://github.com/atom/electron) to match changes in version 1.0 of that project\n\n### 1.2.1\n  - Had to bump package version because 1.2.0 got published to npm as @beta\n\n### 1.2.0\n  - Special logic to resolve correctly when in an [electron](https://github.com/atom/electron) renderer process\n\n### 1.1.0\n  - Special logic to handle an edge case when used in a globally-installed CLI project\n  - Fixed a bug where `setPath()` did not update `require('app-root-path').path`\n  - Moved some logic outside of the `resolve()` function so that it's not called multiple times\n\n### 1.0.0\n  - No changes.  Just updated the version to signify a locked API (see [semver](http://semver.org/)).\n\n### 0.1.1\n  - Added Windows support (and, theoretically, other operating systems that have a directory separator that's not \"/\")\n\n### 0.1.0\n  - Completely rewrote the path resolution method to account for most possible scenarios.  This shouldn't cause and backwards compatibility issues, but always test your code.\n  - Removed the need to pass a modules's `require()` method to the `appRootPath.require()` function.  Which it's true that each module has its own `require()` method, in practice it doesn't matter, and it's **much** simpler this way.\n  - Added tests\n\n\n[build-status]: https://travis-ci.org/inxilpro/node-app-root-path\n[build-status-img]: https://travis-ci.org/inxilpro/node-app-root-path.svg\n[david-dm-img]: https://david-dm.org/inxilpro/node-app-root-path.svg\n[david-dm]: https://david-dm.org/inxilpro/node-app-root-path\n[codecov-img]: https://codecov.io/gh/inxilpro/node-app-root-path/branch/master/graph/badge.svg\n[codecov]: https://codecov.io/gh/inxilpro/node-app-root-path",
  "readmeFilename": "README.md",
  "_id": "app-root-path@1.4.0",
  "_shasum": "6335d865c9640d0fad99004e5a79232238e92dfa",
  "_from": "app-root-path@^1.3.0",
  "_resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-1.4.0.tgz"
}
