libnpmsearch is a Node.js library providing a programmatic API for searching packages within the npm registry and compatible alternative registries. Currently stable at version 9.0.1, it is part of the broader npm CLI ecosystem, benefiting from its active maintenance and continuous integration. The library exclusively utilizes the modern npm search endpoint, explicitly *not* supporting legacy `/-/all` search methods. It differentiates itself by offering detailed search parameters, including sorting by quality, maintenance, and popularity, and integrates seamlessly with `npm-registry-fetch` for robust request configuration, authentication, and caching capabilities. Its release cadence is tied to the npm CLI's development, providing regular updates and bug fixes for modern Node.js environments.
npm install libnpmsearchVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to perform basic and detailed searches using libnpmsearch, including pagination and sorting options. It shows how to retrieve package metadata and score details, highlighting the integration with npm-registry-fetch options like `token`.
Upgrade your Node.js environment to a compatible version (e.g., using nvm or your OS package manager).
Ensure your search queries are compatible with the modern npm search endpoint. This typically means using keywords or package names rather than expecting full registry dumps.
Refer to the `npm-registry-fetch` documentation on npmjs.com for a comprehensive guide on fetch options and authentication configurations.
Implement client-side logic if an exact number of results is critical, such as filtering or truncating the returned array.
Change your import statement to `import search from 'libnpmsearch';` for ESM, or `const search = require('libnpmsearch');` for CommonJS.Refactor your code to use `import search from 'libnpmsearch';`. If you intend to use CommonJS, ensure your `package.json` does not have `"type": "module"` or change your file extension to `.cjs`.
Pass `opts.token` with a valid authentication token obtained from your registry, or ensure your npm client is logged in to the target registry by running `npm login`.