1# find-npm-prefix 2 3Find the npm project directory associated with for a given directory 4 5## USAGE 6 7``` 8const findPrefix = require('find-npm-prefix') 9 10findPrefix(process.cwd).then(prefix => { 11 … 12}) 13``` 14 15## findPrefix(dir) → Promise(prefix) 16 17This computes the npm prefix, that is, the directory that npm adds and 18removes modules from for a given path. 19 20It takes a directory as an argument and returns a promise of the associated 21prefix directory. 22 23## Algorithm 24 251. If the directory is a `node_modules` folder, scan up the tree till you find a non-`node_modules` directory and return that. 262. Else, look for the first parent directory that contains a `node_modules` or a `package.json` 27 1. If one is found, that's the prefix. 28 2. If none are found, return the original directory we were given 29