npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

"npm prefix" doesn't report where 'package.json' is

What I Wanted to Do

Know the current npm prefix

What Happened Instead

Instead of the

closest parent directory to contain a package.json
(from npm-prefix docs)

I get returned the closest parent directory to contain “node_modules”.

Reproduction Steps

mkdir test
cd test/
npm init
npm install jquery
mkdir vendor
cp -r node_modules/ vendor/
npm prefix        # returns "~/test"
cd vendor/
npm prefix        # returns "~/test/vendor"

Details

Platform Info

$ npm --versions
{ npm: '3.10.10',
  ares: '1.10.1-DEV',
  http_parser: '2.8.0',
  icu: '52.1',
  modules: '48',
  napi: '3',
  node: '6.14.4',
  openssl: '1.0.2j-fips',
  uv: '1.16.1',
  v8: '5.1.281.111',
  zlib: '1.2.8' }
$ node -p process.platform
linux


It looks like it’s been that way since forever, so I suppose this is a documentation error, and re-categorized it accordingly.

Edit: keep forgetting the docs are in the repo too, here’s a PR:

https://github.com/npm/cli/pull/116