Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In NPM, How to get the list of packages under a scope?

We are developing custom packages and each package is maintained under the scope. For example:

  1. @nest/common
  2. @nest/core
  3. @nest/microservice

How to get the list of packages available in the particular scope? For e.g I want to view the list of packages under @nest. npm list returns all the packages.

like image 557
Thangaraja Avatar asked Dec 10 '19 12:12

Thangaraja


People also ask

How do I get list of npm packages?

Use the npm list to show the installed packages in the current project as a dependency tree. Use npm list --depth=n to show the dependency tree with a specified depth. Use npm list --prod to show packages in the dependencies . Use npm list --dev to show packages in the devDependencies .

What are npm scoped packages?

Scopes are a way of grouping related packages together, and also affect a few things about the way npm treats the package. Each npm user/organization has their own scope, and only you can add packages in your scope. This means you don't have to worry about someone taking your package name ahead of you.

What is npm list command?

NPM List Command: Lists all the packages as well as their dependencies installed. npm ls. Example: npm ls lists all of the npm packages installed in the package. json file.


1 Answers

npm uses the search api from npms.io [docs], which, includes the following:

Besides normal text, q supports qualifiers to express filters and other modifiers:

  • scope:types: Show/filter results that belong to the @types scope
$ curl -s "https://api.npms.io/v2/search?q=scope:nest" | jq -r '.results[] | .package.name'
@nest/testing
@nest/core
@nest/microservices
@nest/websockets
» npm search scope:nest
NAME                      | DESCRIPTION          | AUTHOR          | DATE       | VERSION  | KEYWORDS
@nest/testing             | Nest - the testing…  | =wbhob          | 2017-12-22 | 4.5.4    |
@nest/core                | Nest - the core…     | =wbhob          | 2017-12-22 | 4.5.4    |
@nest/microservices       | Nest - the…          | =wbhob          | 2017-12-22 | 4.5.4    |
@nest/websockets          | Nest - the…          | =wbhob          | 2017-12-22 | 4.5.4    |

Updated 2022-10-03


Original Answer:

Searching on npm for the explicit scope will return the available public packages for that scope.

For example:

» npm search @nest
NAME                      | DESCRIPTION          | AUTHOR          | DATE
@nest/testing             | Nest - the testing…  | =wbhob          | 2017-12-22
@nest/core                | Nest - the core…     | =wbhob          | 2017-12-22
@nest/websockets          | Nest - the…          | =wbhob          | 2017-12-22
@nest/microservices       | Nest - the…          | =wbhob          | 2017-12-22

If the scope contains more than 20 packages, you need to use the --searchlimit option with a higher limit, like npm --searchlimit=100 search @nestjs

like image 112
forivall Avatar answered Oct 18 '22 02:10

forivall