# app-paths

> Just a basic module to get the base path to the lib, config or other paths for a typical node app

Latest version **0.0.2** (published 2016-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install app-paths
pnpm add app-paths
yarn add app-paths
bun add app-paths
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2016-01-07 |
| First published | 2015-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| Author | Harry Guillermo |
| Maintainers | hguillermo |
| Keywords | require, base, path, lib, config |

## Links

- npm: https://www.npmjs.com/package/app-paths
- npm.io page: https://npm.io/package/app-paths

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) 3.9.3

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.0.2 (latest) — 2016-01-07
- 0.0.1 — 2015-06-10

## README

# app-paths

It helps to get the path relative to the root of the node app.

```js
var basePaths = require('app-paths')();

console.log(basePaths.pathTo('lib')); // APP_PATH/lib
```

#### IMPORTANT

This module only works when you have a node_modules directory in the root of your node application.

# Methods

To start using it require the module:

```js
var basePaths = require('app-paths')();

console.log(basePaths.base()); // APP_PATH/

```
Or you can pass some options:

```js
var options = {
    views: 'path/to/views',
    routes: 'path/to/routes'
}
var basePaths = require('app-paths')(options);

console.log(basePaths.pathTo('routes')); // APP_PATH/path/to/routes

```
## base()

It returns the path to the application root path.

## lib()

It returns the path to the lib path.

## config()

It returns the path to the config path.

## pathTo(dir)

It returns the path to the directory (dir) passed as a parameter relative to the node application.

## fromRoot(filepath) or _(filepath)

It returns the application root path plus the filepath. Useful when you are requiring a module.

Basic example:
```
app
  - lib
  - config
  - node_modules
  - index.js

var basePaths = require('app-paths')();
console.log(basePaths.base());           // /path/to/app/
console.log(basePaths.pathTo('lib'));    // /path/to/app/lib
console.log(basePaths.lib());            // /path/to/app/lib
console.log(basePaths.config());         // /path/to/app/config
console.log(basePaths.pathTo('a/b/c'));  // /path/to/app/a/b/c
```

Another example:

```
app
  - lib
  - config
  - node_modules
  - index.js

var myPaths = {
    views: 'path/to/my/views',
    routes: 'path/to/my/routes',
    assets: 'path/to/my/assets'
}
var basePaths = require('app-paths')(myPaths);

console.log(basePaths.base());           // /path/to/app/
console.log(basePaths.pathTo('lib'));    // /path/to/app/lib
console.log(basePaths.pathTo('a/b/c'));  // /path/to/app/a/b/c

console.log(basePaths.pathTo('views'));  // /path/to/app/path/to/my/views
console.log(basePaths.pathTo('routes')); // /path/to/app/path/to/my/routes
```

.fromRoot(filepath) or ._(filepath) example:

```
app
  - lib
  - config
  - node_modules
  - index.js

var paths = require('app-paths')();

console.log(paths.fromRoot('/my/path/to/models/user'));  // /path/to/app/my/path/to/models/user
console.log(paths._('/my/path/to/models/user'));         // /path/to/app/my/path/to/models/user
```

# Install

With [npm](http://npmjs.org) do:

```
npm install app-paths --save
```
# License

MIT

---
_Source: https://npm.io/package/app-paths · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
