npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@liquid-labs/npm-toolkit

v1.0.0-alpha.21

Published

A programmatic wrapper around key npm functions and package manipulation utilities.

Downloads

210

Readme

npm-toolkit

coverage: 91% Unit tests

A programmatic wrapper around key npm functions and package data manipulation utilities.

Installation

npm i @liquid-labs/npm-toolkit

Usage

import * as fsPath from 'node:path'

import * as npm from '@liquid-labs/npm-toolkit'

const pkgDir = fsPath.join('path', 'to', 'package')
const pkgJSON = await npm.getPackageJSON(( pkgDir ))
const { name, org, basename, version } = npm.getPackageOrgBasenameAndVersion({ pkgJSON })
// alt forms:
// const { name, org, basename, version } = await getPackageOrgBasenameAndVersion({ pkgDir })
// const { name, org, basename, version } = await getPackageOrgBasenameAndVersion('@acme/foo@^1.0')

await nmp.update({ global: true })
await npm.install({ global: true, packages: ['npm-check@latest' ]})

API reference

API generated with dmd-readme-api.

  • Functions:
    • getPackageJSON(): Find and parses the package.json associated with the package containing pkgDir.
    • getPackageOrgBasenameAndVersion(): xtracts the package name, organization, basename, and version from a project's package.json file.
    • getVersion(): Retrieves the version of Node.js and npm installed on the system.
    • install(): Installs packages using npm install.
    • update(): Updates project dependencies or global installs.
    • validatePackageSpec(): Validates that a package specification is safe for use in shell commands and file operations.
    • view(): Retrieves package metadata from the npm registry using npm view.

getPackageJSON(pkgDir)Promise.<Object> source code global index

Find and parses the package.json associated with the package containing pkgDir. The method will check parent directories until it finds a package.json file or runs out of parent directories.

| Param | Type | Description | | --- | --- | --- | | pkgDir | string | The path to the package directory or sub-directory. |

Returns: Promise.<Object> - A promise that resolves to the parsed package.json file.

getPackageOrgBasenameAndVersion(input)Promise.<{name: string, org: string, basename: string, version: string}> source code global index

xtracts the package name, organization, basename, and version from a project's package.json file.

| Param | Type | Description | | --- | --- | --- | | input | string | Object | If a string, it's treated as a package spec (e.g. '@acme/foo@^1.0'). Otherwise, input is an object with exactly one of pkgDir, pkgJSON, or pkgSpec specified. | | [input.pkgDir] | string | The path to the package directory. | | [input.pkgJSON] | Object | The parsed package.json file. | | [input.pkgSpec] | string | The package spec to extract the package name, organization, basename, and version from. This can be a scoped package spec (e.g., @acme/foo@^1.0) or an unscoped package spec (e.g., [email protected]). |

Returns: Promise.<{name: string, org: string, basename: string, version: string}> - A promise that resolves to an object with the package name, organization, basename, and version.

getVersion()Promise.<{nodeVer: string, npmVer: string}> source code global index

Retrieves the version of Node.js and npm installed on the system.

Returns: Promise.<{nodeVer: string, npmVer: string}> - A promise that resolves to an object with the Node.js and npm versions as strings without the v prefix.

install(params)Promise.<{installedPackages: Array.<string>, localPackages: Array.<string>, productionPackages: Array.<string>}> source code global index

Installs packages using npm install.

| Param | Type | Default | Description | | --- | --- | --- | --- | | params | Object | | The parameters for the install function. | | [params.allowFilePackages] | boolean | false | Whether to allow 'file:' protocol package specs (e.g., 'file:../pkg'). | | [params.devPaths] | Array.<string> | | An array of paths to search for local packages. Any local packages found will be used instead of installing from the registry. | | [params.global] | boolean | | Whether to install globally. | | params.packages | Array.<string> | | List of package specifiers to install. At least one package must be specified. | | [params.projectPath] | string | | The path to the project to install. | | [params.saveDev] | boolean | | Whether to save the package as a development dependency. | | [params.saveProd] | boolean | | Whether to save the package as a production dependency. This is the default behavior. | | [params.verbose] | boolean | | Whether to print verbose output. |

Returns: Promise.<{installedPackages: Array.<string>, localPackages: Array.<string>, productionPackages: Array.<string>}> - A promise that resolves to a summary of the installed packages.

update(params)Promise.<{updated: boolean, actions: Array.<string>, result: Object}> source code global index

Updates project dependencies or global installs. Requires at 'global' and/or projectPath be provided.

| Param | Type | Description | | --- | --- | --- | | params | Object | The parameters for the update function. | | [params.dryRun] | boolean | Check for outdated dependecies and display results, but don't actually update. | | [params.global] | boolean | Operate on the globally installed packages instead of projectPath dependencies. One of global and projectPath must be provided. | | [params.packages] | Array.<string> | Only check the named packages. If global is true, this would be a list of global packages and otherwise a list of projectPath dependencies. | | [params.projectPath] | string | The path to the project to update. One of global and projectPath must be provided. |

Returns: Promise.<{updated: boolean, actions: Array.<string>, result: Object}> - A promise that resolves to a summary of the updates.

validatePackageSpec(packageSpec, [options])Object source code global index

Validates that a package specification is safe for use in shell commands and file operations. Supports standard npm package specs and file: protocol packages when allowFilePackages is true.

| Param | Type | Default | Description | | --- | --- | --- | --- | | packageSpec | string | | The package specification to validate (e.g., '[email protected]', '@scope/pkg', 'file:../pkg') | | [options] | Object | | Validation options | | [options.allowFilePackages] | boolean | false | Whether to allow 'file:' protocol package specs | | [options.throwIfInvalid] | boolean | false | If true, throws an error on validation failure. If false, returns result object with isValid=false. |

Returns: Object - Validation result with { isValid: boolean, errorMsg?: string, isFilePackage?: boolean, cleanSpec?: string, packageName?: string, versionPart?: string, resolvedPath?: string }

Throws: Validates that a package specification is safe for use in shell commands and file operations. Supports standard npm package specs and file: protocol packages when allowFilePackages is true.

view(params)Promise.<(Object|null)> source code global index

Retrieves package metadata from the npm registry using npm view.

| Param | Type | Description | | --- | --- | --- | | params | Object | The parameters for the view function. | | params.packageName | string | The name of the package to view. | | [params.throwOnNotFound] | boolean | If true, then a '404' error will throw rather than return null. | | [params.version] | string | The specific version to view. If omitted, returns data for the latest version. |

Returns: Promise.<(Object|null)> - A promise that resolves to the parsed JSON object returned by npm view --json or null if no package info is found.