1

I'm running:

npm ls -g 

And it doesn`t show anything.

I`m pretty sure I have modules installed. If I run:

ls -1 usr/local/lib/node_modules/

The result is:

express
forever
fstream
fstream-ignore
generator-keystone
http-server
keystone
node-debug
node-gyp
node-inspector
npm
yo

The command perfectly works for locally installed modules.

Adding the results of npm config ls -l that maybe could help more.

; cli configs
long = true
user-agent = "npm/3.3.12 node/v4.1.2 darwin x64"

; default values
access = null
also = null
always-auth = false
bin-links = true
browser = null
ca = null
cache = "/Users/ash/.npm"
cache-lock-retries = 10
cache-lock-stale = 60000
cache-lock-wait = 10000
cache-max = null
cache-min = 10
cafile = undefined
cert = null
color = true
depth = null
description = true
dev = false
dry-run = false
editor = "vi"
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
force = false
git = "git"
git-tag-version = true
global = false
globalconfig = "/usr/local/etc/npmrc"
globalignorefile = "/usr/local/etc/npmignore"
group = 20
heading = "npm"
https-proxy = null
if-present = false
ignore-scripts = false
init-author-email = ""
init-author-name = ""
init-author-url = ""
init-license = "ISC"
init-module = "/Users/ash/.npm-init.js"
init-version = "1.0.0"
json = false
key = null
link = false
local-address = undefined
loglevel = "warn"
; long = false (overridden)
message = "%s"
node-version = "4.1.2"
npat = false
onload-script = null
only = null
optional = true
parseable = false
prefix = "/usr/local"
production = false
progress = true
proprietary-attribs = true
proxy = null
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
rollback = true
save = false
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-prefix = "^"
scope = ""
searchexclude = null
searchopts = ""
searchsort = "name"
shell = "/bin/bash"
shrinkwrap = true
sign-git-tag = false
strict-ssl = true
tag = "latest"
tag-version-prefix = "v"
tmp = "/var/folders/3r/9ljlgw6j7m53hwxm_3c3gdkw000106/T"
umask = 18
unicode = true
unsafe-perm = true
usage = false
user = 501
; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden)
userconfig = "/Users/ash/.npmrc"
version = false
versions = false
viewer = "man"
sparaflAsh
  • 646
  • 1
  • 9
  • 26
  • If you install a package with the `-g` flag, does it land in your `/usr/local/lib/node_modules/` directory? Or does it get installed elsewhere? – Matthew Bakaitis Nov 12 '15 at 17:45
  • Yes. I just installed socket.io to try figure out and it's been placed in that folder. – sparaflAsh Nov 13 '15 at 10:02
  • `npm ls -g` should work fine. It looks like some configuration of environmental problem. – Leonid Beschastny Nov 13 '15 at 10:07
  • I read somewhere that may be some wrong indication in `prefix = "/usr/local"` that should be set to usr/local/lib/node_modules/, but I can't locate the file where this is specified. It is supposed to be a .npmrc file. – sparaflAsh Nov 13 '15 at 10:11
  • Ok. No need to locate the file because it's possible to change prefix with: `npm config set prefix /usr/local/ -g` anyway, but nothing really changes and still no modules displayed. – sparaflAsh Nov 13 '15 at 10:19

1 Answers1

0

So I solved the issue in a brutal way, but at the end of the answer you will find suggestions to be more gentle with your machine.

I actually reinstalled node. Before doing this I deleted everything of the previous installation as suggested in some other post.

Here is the direct link to the script suggested in the previous post.

For the rest you should already know how to install Node.

Lesson learned: Use always nvm and think a couple of times before installing/uninstalling with -g option.

Now npm ls -g --depth=0 works as a charm:

/usr/local/lib
├── generator-keystone@0.3.9
├── npm@2.14.7
└── yo@1.5.0

I was then curios about the changing of the config file.

I've run again: npm config ls -l

It starts similar:

; cli configs
long = true
user-agent = "npm/2.14.7 node/v4.2.2 darwin x64"

Then come these new lines that were missing:

; globalconfig /usr/local/etc/npmrc
prefix = "/usr/local"

And then remains the same:

; default values
access = null
[..]

So, a more fit answer would be as it follows.

I haven't tested it in the end, but if you installed everything by default theres a file npmrc in /usr/local/etc. To make it point to the right location you should run:

npm config set globalconfig /etc/npmrc

For details on globalconfig

Hope that's all folks.

Community
  • 1
  • 1
sparaflAsh
  • 646
  • 1
  • 9
  • 26