LinuxCommandLibrary

npm-list

List installed npm packages and dependencies

TLDR

View documentation for the original command

$ tldr npm ls
copy

SYNOPSIS

npm list [package_name]

PARAMETERS

--global
    Lists globally installed packages instead of local packages.

--depth
    Specifies the maximum depth of dependencies to display. Defaults to `Infinity`.

--json
    Outputs the dependency tree in JSON format.

--long
    Displays extended information about each package.

--parseable
    Outputs the list in a parseable format.

--all
    Shows all installed packages including extraneous or invalid ones.

--omit
    Omit either 'dev', 'optional', or 'peer' dependencies from the results.

--include
    Include either 'dev', 'optional', or 'peer' dependencies in the results.


    Optional. Lists dependencies of a specific package.

DESCRIPTION

The `npm list` command displays a tree-structured view of installed npm packages in the current directory or a specified directory. It provides information about the installed packages, their versions, and their dependencies. This command is invaluable for understanding the project's dependency structure, identifying potential conflicts, and verifying that all necessary packages are installed correctly. You can optionally specify a package to list only that package's dependencies. It reads the `package.json` file to determine the project's dependencies and traverses the `node_modules` directory to identify installed packages. The output can be customized with various options to control the level of detail and the format of the displayed information. The command is primarily used by developers to manage and inspect the dependencies of their Node.js projects.

CAVEATS

The output can be very verbose for projects with a large number of dependencies. Global package listing may require elevated privileges if npm was installed globally with a restricted user.

EXIT CODES

The `npm list` command exits with a status code of 0 if it completes successfully. Non-zero exit codes indicate errors, such as an invalid package name or a problem accessing the file system.

EXAMPLE USAGE

npm list
Lists all dependencies in the current directory.

npm list --depth 1
Lists dependencies only one level deep.

npm list --global
Lists globally installed packages.

npm list lodash
Lists only the lodash package and its dependencies.

HISTORY

The `npm list` command has been a part of npm since its early versions, evolving alongside the Node.js ecosystem. Its purpose has always been to provide a clear view of project dependencies. Over time, new options and features have been added to enhance its functionality and flexibility, such as JSON output and depth control. This command reflects npm's commitment to robust dependency management.

SEE ALSO

npm install(1), npm uninstall(1), npm outdated(1)

Copied to clipboard