Check for outdated, incorrect, and unused dependencies in npm projects.
npx @tessl/cli install tessl/npm-npm-check@6.0.0npm-check is a comprehensive Node.js library and command-line tool that analyzes npm projects to identify outdated, incorrect, and unused dependencies. It provides an interactive CLI interface for safely updating packages, supports both local and global dependency checking, and works with public and private npm registries.
npm install -g npm-check or npm install npm-checkconst npmCheck = require('npm-check');For TypeScript:
import npmCheck from 'npm-check';const npmCheck = require('npm-check');
// Basic usage - check current directory
npmCheck()
.then(currentState => {
const packages = currentState.get('packages');
packages.forEach(pkg => {
console.log(`${pkg.moduleName}: ${pkg.installed} -> ${pkg.latest}`);
});
});
// With options
npmCheck({
global: false,
skipUnused: false,
ignoreDev: false,
cwd: './my-project'
})
.then(currentState => {
// Process results
const outdatedPackages = currentState.get('packages')
.filter(pkg => pkg.bump && !pkg.notInstalled);
});# Check current directory
npm-check
# Interactive update mode
npm-check -u
# Check global packages
npm-check -g
# Update all packages without prompting
npm-check -y
# Check only production dependencies
npm-check -p
# Skip unused dependency check
npm-check -snpm-check is built around several key components:
Core programmatic interface for integrating npm-check functionality into other tools and scripts.
function npmCheck(options?: NpmCheckOptions): Promise<CurrentState>;
interface NpmCheckOptions {
global?: boolean;
update?: boolean;
updateAll?: boolean;
skipUnused?: boolean;
devOnly?: boolean;
ignoreDev?: boolean;
cwd?: string;
saveExact?: boolean;
currentState?: Object;
ignore?: string | string[];
specials?: string;
debug?: boolean;
emoji?: boolean;
spinner?: boolean;
installer?: 'npm' | 'pnpm' | 'yarn' | 'ied' | 'auto';
}
interface CurrentState {
get(key: string): any;
set(key: string, value: any): void;
all(): Object;
inspectIfDebugMode(): void;
}Full-featured CLI for interactive and automated dependency management workflows.
npm-check [path] [options]
Options:
-u, --update Interactive update
-y, --update-all Update all without prompting
-g, --global Check global modules
-s, --skip-unused Skip unused package check
-p, --production Skip devDependencies
-d, --dev-only Only check devDependencies
-i, --ignore <glob> Ignore dependencies by glob
-E, --save-exact Save exact versions
--specials <list> Depcheck specials to include
--no-color Disable color output
--no-emoji Disable emoji output
--debug Enable debug outputinterface PackageInfo {
moduleName: string;
homepage: string;
regError: any;
pkgError: any;
latest: string;
installed: string;
isInstalled: boolean;
notInstalled: boolean;
packageWanted: string;
packageJson: string;
devDependency: boolean;
usedInScripts: string[] | undefined;
mismatch: boolean;
semverValid: string;
easyUpgrade: boolean;
bump: 'patch' | 'minor' | 'major' | 'prerelease' | 'build' | 'nonSemver' | null;
unused: boolean;
}
type StateKey =
| 'packages' // Array of PackageInfo objects
| 'debug' // Debug mode status
| 'global' // Global mode status
| 'cwd' // Current working directory
| 'cwdPackageJson' // Parsed package.json object
| 'emoji' // Emoji mode status
| 'globalPackages' // Global packages data
| 'unusedDependencies' // Unused dependencies array
| 'missingFromPackageJson' // Missing packages object
| 'update' // Update mode status
| 'updateAll' // Update all mode status
| 'skipUnused' // Skip unused check status
| 'devOnly' // Dev only mode status
| 'ignoreDev' // Ignore dev dependencies status
| 'saveExact' // Save exact versions status
| 'specials' // Depcheck specials
| 'spinner' // Spinner enabled status
| 'installer' // Package installer to use
| 'ignore'; // Ignore patterns for dependencies