# find-npm-prefix

> Find the npm project directory associated with for a given directory

Latest version **1.0.2** (published 2017-11-21) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install find-npm-prefix
pnpm add find-npm-prefix
yarn add find-npm-prefix
bun add find-npm-prefix
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-11-21 |
| First published | 2017-11-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Rebecca Turner |
| Maintainers | iarna |

## Links

- npm: https://www.npmjs.com/package/find-npm-prefix
- Repository: https://github.com/npm/find-npm-prefix
- Homepage: https://github.com/npm/find-npm-prefix#readme
- Issues: https://github.com/npm/find-npm-prefix/issues
- npm.io page: https://npm.io/package/find-npm-prefix

## Recent versions

- 1.0.2 (latest) — 2017-11-21
- 1.0.1 — 2017-11-08
- 1.0.0 — 2017-11-08

## README

# find-npm-prefix

Find the npm project directory associated with for a given directory

## USAGE

```
const findPrefix = require('find-npm-prefix')

findPrefix(process.cwd).then(prefix => {
  …
})
```

## findPrefix(dir) → Promise(prefix)

This computes the npm prefix, that is, the directory that npm adds and
removes modules from for a given path. 

It takes a directory as an argument and returns a promise of the associated
prefix directory.

## Algorithm

1. If the directory is a `node_modules` folder, scan up the tree till you find a non-`node_modules` directory and return that.
2. Else, look for the first parent directory that contains a `node_modules` or a `package.json`
  1. If one is found, that's the prefix.
  2. If none are found, return the original directory we were given

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