code: def _find_modules_in_npm_cache(self):
          
          output = {}
          # with chroot=True (default) the command fails when run as non-root
          user_cache = self.get_command_output("npm cache ls", chroot=False)
          if user_cache['status'] == 0:
              # filter out dirs with .cache.json ('registry.npmjs.org')
              for package in [l for l in user_cache['output'].splitlines()
                              if l.endswith('package.tgz')]:
                  five_tuple = package.split(os.path.sep)
                  if len(five_tuple) != 5:  # sanity check
                      continue
                  home, cache, name, version, package_tgz = five_tuple
                  if name not in output:
                      output[name] = [version]
                  else:
                      output[name].append(version)
          self._log_debug("modules in cache: %s" % output)
  
          outfn = self._make_command_filename("npm_cache_modules")
          self.add_string_as_file(json.dumps(output), outfn)
docs: Example 'npm cache ls' output
              ~/.npm
              ~/.npm/acorn
              ~/.npm/acorn/1.2.2
              ~/.npm/acorn/1.2.2/package.tgz
              ~/.npm/acorn/1.2.2/package
              ~/.npm/acorn/1.2.2/package/package.json
              ~/.npm/acorn/4.0.3
              ~/.npm/acorn/4.0.3/package.tgz
              ~/.npm/acorn/4.0.3/package
              ~/.npm/acorn/4.0.3/package/package.json
              ~/.npm/registry.npmjs.org
              ~/.npm/registry.npmjs.org/acorn
              ~/.npm/registry.npmjs.org/acorn/.cache.json
  
          https://docs.npmjs.com/cli/cache