[英]How to list npm user-installed packages
How do I list the user-installed / environment package only in npm?如何仅在 npm 中列出用户安装/环境 package?
When I do npm -g list
, it outputs every package and their dependencies.当我执行
npm -g list
时,它会输出每个 package 及其依赖项。 Instead I'd like to see the packages installed in the current working project or environment.相反,我希望看到安装在当前工作项目或环境中的包。
npm list -g --depth=0
-g
option it only shows the current directory's packages) -g
选项它只显示当前目录的包)您可以使用以下命令获取所有全局安装模块的列表:
ls `npm root -g`
As of 13 December 2015截至 2015 年 12 月 13 日
Whilst I found the accepted answer 100% correct, and useful, wished to expand upon it a little based on my own experiences, and hopefully for the benefit of others too.虽然我发现接受的答案 100% 正确且有用,但希望根据我自己的经验对其进行一些扩展,并希望也能造福他人。 (Here I am using the terms package and module interchangeably)
(这里我交替使用术语包和模块)
In answer to the question, yes the accepted answer would be:在回答这个问题时,是的,接受的答案是:
npm list -g --depth=0
You might wish to check for a particular module installed globally, on *nix systems / when grep available.您可能希望检查在 *nix 系统上/当 grep 可用时全局安装的特定模块。 This is particularly useful when checking what version of a module you are using (globally installed, just remove the -g flag if checking a local module):
这在检查您正在使用的模块的版本时特别有用(全局安装,如果检查本地模块,只需删除 -g 标志):
npm list -g --depth=0 | grep <module_name>
If you'd like to see all available (remote) versions for a particular module, then do:如果您想查看特定模块的所有可用(远程)版本,请执行以下操作:
npm view <module_name> versions
Note, versions is plural.注意, versions是复数。 This will give you the full listing of versions to choose from.
这将为您提供可供选择的版本的完整列表。
For latest remote version:对于最新的远程版本:
npm view <module_name> version
Note, version is singular.注意,版本是单数。
To find out which packages need to be updated, you can use要找出需要更新的软件包,您可以使用
npm outdated -g --depth=0
To update global packages, you can use要更新全局包,您可以使用
npm update -g <package>
To update all global packages, you can use:要更新所有全局包,您可以使用:
npm update -g
(However, for npm versions less than 2.6.1, please also seethis link as there is a special script that is recommended for globally updating all packages). (但是,对于低于 2.6.1 的 npm 版本,请参阅此链接,因为有一个特殊的脚本建议用于全局更新所有包)。
The above commands should work across NPM versions 1.3.x, 1.4.x, 2.x and 3.x上述命令应该适用于 NPM 版本 1.3.x、1.4.x、2.x 和 3.x
This is what I personally prefer and it may be for others too, it may also help during presentations or meetings.这是我个人更喜欢的,可能对其他人也是如此,它也可能在演示或会议期间有所帮助。
With npm-gui
you can list local and global packages with a better visualization.使用
npm-gui
,您可以以更好的可视化方式列出本地和全局包。
You can find the package at您可以在以下位置找到包裹
Run the following运行以下
//Once
npm install -g npm-gui
cd c:\your-prject-folder
npm-gui localhost:9000
Then open your browser at http:\\localhost:9000
然后在
http:\\localhost:9000
打开浏览器
For local modules: 对于本地模块:
npm list --depth=0
For global modules: 对于全球模块:
npm list -g --depth=0
For project dependencies use:对于项目依赖项,请使用:
npm list --depth=0
For global dependencies use:对于全局依赖项,请使用:
npm list -g --depth=0
npm ls
npm list
is just an alias for npm ls
npm list
只是npm ls
的别名
For the extended info use对于扩展信息使用
npm la
npm ll
You can always set --depth=0
at the end to get the first level deep.您始终可以在最后设置
--depth=0
以获得第一级深度。
npm ls --depth=0
You can check development and production packages.您可以检查开发和生产包。
npm ls --only=dev
npm ls --only=prod
To show the info in json
format以
json
格式显示信息
npm ls --json=true
The default is false
默认为
false
npm ls --json=false
You can insist on long format to show extended information.您可以坚持使用长格式来显示扩展信息。
npm ls --long=true
You can show parseable output instead of tree view.您可以显示可解析的输出而不是树视图。
npm ls --parseable=true
You can list packages in the global install prefix instead of in the current project.您可以在全局安装前缀中而不是在当前项目中列出包。
npm ls --global=true
npm ls -g // shorthand
Node has a concept of Local modules & Global modules Node 有本地模块和全局模块的概念
Local module s are located within current project directory.本地模块位于当前项目目录中。
Global Modules are generally located at user's home directory, though we can change the path where global modules resides.全局模块通常位于用户的主目录,但我们可以更改全局模块所在的路径。
npm list
npm list
npm list --global
OR npm list --g
// It will list all the top level modules with its dependenciesnpm list --global
OR npm list --g
// 它将列出所有顶级模块及其依赖项npm list -g --depth=0
npm list -g --depth=0
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
I use npm -g outdated --depth=0
to list outdated versions我使用
npm -g outdated --depth=0
列出过时的版本
in the global space.在全球空间。
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
You can try NPM Desktop manager你可以试试NPM 桌面管理器
With just one click, you can install/uninstall packages in dev
or global
status.只需单击一下,您就可以在
dev
或global
状态下安装/卸载包。
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
As the end of 2021, there are few obvious way to do it, despite all the other answer are still working I think an update is needed besides a more defined and complete list of commands possible, and while am I at it, I added some other common commands for whom needs it (install, uninstall etc..)到 2021 年底,几乎没有明显的方法可以做到这一点,尽管所有其他答案仍然有效,我认为除了可能的更定义和完整的命令列表之外,还需要更新,而当我在它的时候,我添加了一些需要它的其他常用命令(安装、卸载等)
# bare command
npm list
# ls is an alias of list
npm ls
# don't shows dependencies
npm list --depth=0
# Global modules
npm list -g --depth=0
# More info
npm la
npm ll
# show particual env packages
npm ls --only=dev
npm ls --only=prod
# parseable view (tree view)
npm ls --parseable=true
The Node.js Documentation is actually pretty well explained regarding the matter, this is a collective list of the main commands. Node.js 文档实际上对此事进行了很好的解释,这是主要命令的集合列表。
Before start NOTE:开始之前注意:
All Commands will run the list of installed modules Locally .所有命令都将在本地运行已安装模块的列表。 In order to run global level just add a
-g
flag at the end of the statement.为了运行全局级别,只需在语句末尾添加一个
-g
标志。
See the version of all installed npm packages, including their dependencies .查看所有已安装 npm 包的版本,包括它们的依赖项。
❯ npm list >>> /Users/joe/dev/node/cowsay └─┬ cowsay@1.3.1 ├── get-stdin@5.0.1 ├─┬ optimist@0.6.1 │ ├── minimist@0.0.10 │ └── wordwrap@0.0.3 ├─┬ string-width@2.1.1 │ ├── is-fullwidth-code-point@2.0.0 │ └─┬ strip-ansi@4.0.0 │ └── ansi-regex@3.0.0 └── strip-eof@1.0.0
Get only your top-level packages只获取您的顶级包
npm list --depth=0
Get the version of a specific package by specifying its name.通过指定名称获取特定包的版本。
npm list <package-name>
See what's the latest available version of the package on the npm repository在 npm 存储库上查看该软件包的最新可用版本是什么
npm view <package-name> version
Install an old version of an npm package using the @ syntax使用 @ 语法安装旧版本的 npm 包
npm install @ npm install cowsay@1.2.0 npm install@npm install cowsay@1.2.0
Listing all the previous versions of a package列出软件包的所有先前版本
npm view cowsay versions [ '1.0.0', '1.0.1', '1.0.2', '1.0.3', '1.1.0', '1.1.1', '1.1.2', '1.1.3', .... ]
Install new minor or patch release安装新的次要版本或补丁版本
npm update
Install new minor or patch release but not update package.json安装新的次要版本或补丁版本,但不更新 package.json
npm update --no-save
To discover new releases of the packages, this gives you the list of a few outdated packages in one repository that wasn't updated for quite a while为了发现软件包的新版本,这会为您提供一个存储库中的一些过时软件包的列表,这些软件包已经有一段时间没有更新了
npm outdated
Some of those updates are major releases.
其中一些更新是主要版本。 Running npm update won't update the version of those.
运行 npm update 不会更新这些版本。 Major releases are never updated in this way because they (by definition) introduce breaking changes, and npm wants to save you trouble.
主要版本永远不会以这种方式更新,因为它们(根据定义)引入了重大更改,而 npm 想为您省去麻烦。
To update all packages to a new major version, install the npm-check-updates package globally:要将所有包更新到新的主要版本,请全局安装 npm-check-updates 包:
npm install -g npm-check-updates
ncu -u
This will upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version
这会将 package.json 文件中的所有版本提示升级为依赖项和 devDependencies,因此 npm 可以安装新的主要版本
Install in development dependencies.安装在开发依赖项中。
npm install <package-name> -D
npm install <package-name> --save-dev # same as above
Avoid installing those development dependencies in Production with避免在生产环境中安装这些开发依赖项
npm install --production
npm uninstall <package-name>
npm uninstall -g <package-name> # globally uninstall
Uninstall a package and ** remove the reference in the package.json**卸载一个包并**删除package.json中的引用**
npm uninstall <package-name> -S npm uninstall <package-name> --save # same as above
Some commands with global flag examples.一些带有全局标志示例的命令。
npm list -g
npm list --depth=0 -g
npm list <package-name> -g
npm view <package-name> version -g
For Local module use npm list --depth 0
对于本地模块使用
npm list --depth 0
Foe Global module npm list -g --depth 0
敌人全局模块
npm list -g --depth 0
Example local npm module Example global npm module本地 npm 模块示例 全局 npm模块示例
Use npm list
and filter by contains using grep
使用
npm list
并使用grep
按包含过滤
Example:例子:
npm list -g | grep name-of-package
作为速记,您可以运行:
npm ls -g --depth=0
I am using npm version 7.20.3, and it looks the default depth is 0 already.我正在使用 npm 版本 7.20.3,它看起来默认深度已经是 0。 So in my case,
npm list --global
showed only one installed package (npm).所以在我的例子中,
npm list --global
只显示了一个已安装的包(npm)。 I knew I had a lot more packages installed, and I was puzzled at the output.我知道我安装了更多的软件包,我对输出感到困惑。
Eventually, I tried the --depth
param and I was able to see all the packages installed: npm list --global --depth=1
to see the other packages installed.最终,我尝试了
--depth
参数,我能够看到安装的所有包: npm list --global --depth=1
以查看安装的其他包。 (Set to say 10 to see the whole dependency tree). (设置为 10 以查看整个依赖关系树)。
>= v7.0.0: >= v7.0.0:
npm ls -g
< v7.0.0: < v7.0.0:
npm ls -g --depth=0
npm ls
only prints the first level of dependencies by default.npm ls
默认只打印第一级依赖。 You can make it print more of the tree by using--depth=<n>
to set a specific depth, or--all
to print all of them.您可以通过使用
--depth=<n>
设置特定深度或使用--all
打印所有树来使其打印更多树。
For the latest release, see npm Docs: https://docs.npmjs.com/cli/v8/commands/npm-ls#depth有关最新版本,请参阅 npm 文档: https ://docs.npmjs.com/cli/v8/commands/npm-ls#depth
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.