2013-07-30 03:45
采纳率: 0%
浏览 414

如何列出 npm 用户安装的软件包?

How do I list the user-installed package ONLY in npm? When I do npm -g list it outputs every package and their dependencies, which is not what I want.


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

12条回答 默认 最新

  • ℙℕℤℝ 2014-08-26 02:20

    This works pretty well too: npm list -g --depth=0

    • npm: the Node package manager command line tool
    • 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)
    • depth 0 / — depth=0: avoid including every package’s dependencies in the tree view


    点赞 打赏 评论
  • python小菜 2013-07-30 03:54

    One way might be to find the root directory of modules using:

    npm root

    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

    点赞 打赏 评论
  • 游.程 2013-07-30 07:18

    Node_modules contains user-installed packages so change the directory to node_modules and list the items. Core Modules are defined in node's source in the lib/ folder.


         example@example:~/:~/node_modules$ ls
         express  maxmind-native  node-whois  ua-parser-js
         geoip    mongoskin       pdfkit      tail       zeromq
         maxmind  nodemailer      request     ua-parser  zmq
    点赞 打赏 评论
  • You can get a list of all globally installed modules using:

    ls `npm root -g`

    点赞 打赏 评论
  • To see list of all packages that are installed.

    $ npm ls --parseable | awk '{gsub(/\/.*\//,"",$1); print}'| sort -u

    show parseable of npm packages list

    点赞 打赏 评论
  • elliott.david 2015-12-13 00:20

    As of 13 December 2015

    npm list illustration

    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. (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. 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):

    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. 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 see this link as there is a special script that is recommended for globally updating all packages).

    The above commands should work across NPM versions 1.3.x, 1.4.x, 2.x and 3.x

    点赞 打赏 评论
  • 旧行李 2016-02-16 16:16

    Node has a concept of Local modules & Global modules

    Local modules 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.

    1. Lists local modules within current dir: npm list
    2. Lists global modules : npm list --global OR npm list --g // It will list all the top level modules with its dependencies
    3. List only top level(Installed modules) global modules : npm list -g --depth=0
    点赞 打赏 评论
  • 狐狸.fox 2016-04-28 04:44

    For local modules:

    npm list --depth=0

    For global modules:

    npm list -g --depth=0
    点赞 打赏 评论
  • 胖鸭 2016-05-31 14:51

    For project dependencies use:

    npm list --depth=0

    For global dependencies use:

    npm list -g --depth=0
    点赞 打赏 评论
  • Memor.の 2016-11-24 10:37
    npm ls

    npm list is just an alias for 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.

    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

    npm ls --json=true

    The default is 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

    Full documentation you can find here.

    点赞 打赏 评论
  • bug^君 2016-12-31 10:45

    I use npm -g outdated --depth=0 to list outdated versions
    in the global space.

    点赞 打赏 评论
  • 妄徒之命 2017-08-23 12:29

    I prefer tools with some friendly gui!

    I used npm-gui which gives you list of local and global packages

    The package is at and

    npm install -g npm-gui
    cd c:\your-prject-folder
    npm-gui localhost:9000

    At your browser http:\\localhost:9000


    点赞 打赏 评论

相关推荐 更多相似问题