本文翻译自:How to list npm user-installed packages?
How do I list the user-installed package ONLY in npm
? 如何仅在npm
列出用户安装的软件包? When I do npm -g list
it outputs every package and their dependencies, which is not what I want. 当我执行npm -g list
它会输出每个包及其依赖项,这不是我想要的。
#1楼
参考:https://stackoom.com/question/1DGTw/如何列出npm用户安装的软件包
#2楼
One way might be to find the root directory of modules using: 一种方法可能是使用以下方法查找模块的根目录:
npm root
/Users/me/repos/my_project/node_modules
And then list that directory... 然后列出该目录......
ls /Users/me/repos/my_project/node_modules
grunt grunt-contrib-jshint
The user-installed packages in this case are grunt and grunt-contrib-jshint 在这种情况下,用户安装的包是grunt和grunt-contrib-jshint
#3楼
Node_modules contains user-installed packages so change the directory to node_modules and list the items. Node_modules包含用户安装的软件包,因此将目录更改为node_modules并列出项目。 Core Modules are defined in node's source in the lib/
folder. 核心模块在lib/
文件夹的节点源中定义。
Example:
example@example:~/:~/node_modules$ ls
express maxmind-native node-whois socket.io ua-parser-js
geoip mongoskin pdfkit tail zeromq
maxmind nodemailer request ua-parser zmq
#4楼
您可以使用以下命令获取所有全局安装模块的列表:
ls `npm root -g`
#5楼
This works pretty well too: npm list -g --depth=0
这也很好用: npm list -g --depth=0
- npm : the Node package manager command line tool npm :Node包管理器命令行工具
- list -g : display a tree of every package found in the user's folders (without the -g option it only shows the current directory's packages) list -g :显示在用户文件夹中找到的每个包的树(没有-g选项,它只显示当前目录的包)
- depth 0 / — depth=0 : avoid including every package's dependencies in the tree view depth 0 / - depth = 0 :避免在树视图中包含每个包的依赖关系
#6楼
To see list of all packages that are installed. 查看已安装的所有软件包的列表。
$ npm ls --parseable | awk '{gsub(/\/.*\//,"",$1); print}'| sort -u
show parseable of npm packages list https://docs.npmjs.com/cli/ls#parseable 显示可解析的npm包列表https://docs.npmjs.com/cli/ls#parseable