depcheck vs snyk vs npm-check-updates vs retire
NPM Package Management and Security Tools Comparison
1 Year
depchecksnyknpm-check-updatesretireSimilar Packages:
What's NPM Package Management and Security Tools?

These tools are essential for maintaining the health and security of Node.js applications. They help developers identify unused dependencies, check for outdated packages, detect vulnerabilities, and ensure that dependencies are safe to use. Using these tools can significantly enhance the reliability and security of applications by keeping dependencies up to date and minimizing risks associated with outdated or vulnerable packages.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
depcheck1,080,9874,826231 kB116a year agoMIT
snyk457,8265,03548.9 MB1303 hours agoApache-2.0
npm-check-updates447,4159,6405.3 MB773 days agoApache-2.0
retire73,9993,77289.6 kB24 months agoApache-2.0
Feature Comparison: depcheck vs snyk vs npm-check-updates vs retire

Dependency Management

  • depcheck:

    depcheck analyzes your project to identify dependencies that are declared in package.json but are not actually used in your code. This helps you keep your project clean and efficient by removing unnecessary packages that can bloat your application.

  • snyk:

    snyk not only identifies vulnerabilities in your dependencies but also provides actionable fixes and ongoing monitoring. It integrates with your development workflow to ensure that any new vulnerabilities are detected and addressed promptly.

  • npm-check-updates:

    npm-check-updates allows you to check for the latest versions of your dependencies and update your package.json file accordingly. It simplifies the process of keeping your packages up to date, ensuring that you benefit from the latest features and security patches.

  • retire:

    retire focuses on identifying outdated packages that have known vulnerabilities. It scans your project and cross-references your dependencies against a database of known security issues, helping you to proactively manage security risks in your application.

Security Features

  • depcheck:

    depcheck does not directly address security but helps maintain a clean environment by removing unused packages, which can reduce the attack surface of your application.

  • snyk:

    snyk offers robust security features, including vulnerability scanning, automated fixes, and continuous monitoring. It helps you to maintain a secure application by keeping track of vulnerabilities in real-time.

  • npm-check-updates:

    npm-check-updates does not focus on security but ensures that you are using the latest versions of your dependencies, which may include important security updates.

  • retire:

    retire is specifically designed to identify known vulnerabilities in your dependencies. It provides alerts for outdated packages that have security issues, allowing you to take immediate action to secure your application.

Ease of Use

  • depcheck:

    depcheck is straightforward to use; you simply run it in your project directory, and it provides a list of unused dependencies. However, it may require manual intervention to remove them from package.json.

  • snyk:

    snyk has a user-friendly interface and integrates well with various development tools. It provides detailed reports and suggestions for fixing vulnerabilities, making it accessible for developers of all skill levels.

  • npm-check-updates:

    npm-check-updates is user-friendly and allows you to quickly see which packages need updating. You can easily update your package.json with a single command, making it convenient for developers.

  • retire:

    retire is easy to implement and provides clear output regarding vulnerabilities. However, it may require additional configuration for optimal use in larger projects.

Integration

  • depcheck:

    depcheck can be easily integrated into your build process, allowing you to check for unused dependencies as part of your CI/CD pipeline, ensuring that your project remains clean throughout its lifecycle.

  • snyk:

    snyk offers extensive integration options with popular CI/CD tools, GitHub, and other platforms, enabling continuous monitoring and automatic alerts for vulnerabilities, making it a powerful tool for maintaining security.

  • npm-check-updates:

    npm-check-updates can be integrated into your development workflow, allowing you to periodically check for updates and keep your dependencies current without manual checks.

  • retire:

    retire can be integrated into your CI/CD pipeline to automatically check for vulnerabilities during the build process, ensuring that security is a continuous concern in your development cycle.

Community and Support

  • depcheck:

    depcheck has a supportive community and is widely used, but it may not have as extensive documentation or support channels as some larger tools.

  • snyk:

    snyk has a strong community and offers extensive documentation, tutorials, and support channels, making it a well-supported option for developers concerned about security.

  • npm-check-updates:

    npm-check-updates is popular among developers and has a good community presence, providing ample resources and examples for troubleshooting and usage.

  • retire:

    retire has a dedicated user base and provides useful documentation, although it may not have as large a community as some other tools.

How to Choose: depcheck vs snyk vs npm-check-updates vs retire
  • depcheck:

    Choose depcheck if you need to identify and remove unused dependencies in your project. It helps maintain a clean package.json and reduces the size of your application by eliminating unnecessary packages.

  • snyk:

    Choose snyk if you want a comprehensive solution for monitoring and fixing vulnerabilities in your dependencies. Snyk provides detailed reports, automated fixes, and continuous monitoring, making it ideal for projects where security is a top priority.

  • npm-check-updates:

    Select npm-check-updates if your primary goal is to upgrade your dependencies to their latest versions. It allows you to easily see which packages are outdated and update them in your package.json file without installing them immediately.

  • retire:

    Opt for retire if you want to focus on security by detecting known vulnerabilities in your dependencies. It scans your project for outdated packages and alerts you to any that have known security issues, ensuring that you can take action to mitigate risks.

README for depcheck

depcheck

Depcheck is a tool for analyzing the dependencies in a project to see: how each dependency is used, which dependencies are useless, and which dependencies are missing from package.json.

Status

Build Status Financial Contributors on Open Collective Build status codecov.io

Dependencies

Installation

npm install -g depcheck

Or simply using npx which is a package runner bundled in npm:

$ npx depcheck

Notice: depcheck needs node.js >= 10.

Syntax Support

Depcheck not only recognizes the dependencies in JavaScript files, but also supports these syntaxes:

To get the syntax support by external dependency, please install the corresponding package explicitly. For example, for TypeScript user, install depcheck with typescript package:

npm install -g depcheck typescript

Special

The special component is used to recognize the dependencies that are not generally used in the above syntax files. The following scenarios are supported by specials:

  • babel - Babel presets and plugins
  • bin - Dependencies used in npm commands, Travis scripts or other CI scripts
  • commitizen - Commitizen configuration adaptor
  • eslint - ESLint configuration presets, parsers and plugins
  • feross-standard - Feross standard format parser
  • gatsby - Gatsby configuration parser
  • gulp-load-plugins - Gulp-load-plugins lazy loaded plugins
  • husky - Husky configuration parser
  • istanbul - Istanbul nyc configuration extensions
  • jest - Jest properties in Jest Configuration
  • karma - Karma configuration frameworks, browsers, preprocessors and reporters
  • lint-staged - Lint-staged configuration parser
  • mocha - Mocha explicit required dependencies
  • prettier - Prettier configuration module
  • tslint - TSLint configuration presets, parsers and plugins
  • ttypescript - ttypescript transformers
  • webpack - Webpack loaders
  • serverless- Serverless plugins

The logic of a special is not perfect. There might be false alerts. If this happens, please open an issue for us.

Usage

depcheck [directory] [arguments]

The directory argument is the root directory of your project (where the package.json file is). If unspecified, defaults to current directory.

All of the arguments are optional:

--ignore-bin-package=[true|false]: A flag to indicate if depcheck ignores the packages containing bin entry. The default value is false.

--skip-missing=[true|false]: A flag to indicate if depcheck skips calculation of missing dependencies. The default value is false.

--json: Output results in JSON. When not specified, depcheck outputs in human friendly format.

--oneline: Output results as space separated string. Useful for copy/paste.

--ignores: A comma separated array containing package names to ignore. It can be glob expressions. Example, --ignores="eslint,babel-*".

--ignore-dirs: DEPRECATED, use ignore-patterns instead. A comma separated array containing directory names to ignore. Example, --ignore-dirs=dist,coverage.

--ignore-path: Path to a file with patterns describing files to ignore. Files must match the .gitignore spec. Example, --ignore-path=.eslintignore.

--ignore-patterns: Comma separated patterns describing files to ignore. Patterns must match the .gitignore spec. Example, --ignore-patterns=build/Release,dist,coverage,*.log.

--quiet: Suppress the "No depcheck issue" log. Useful in a monorepo with multiple packages to focus only on packages with issues.

--help: Show the help message.

--parsers, --detectors and --specials: These arguments are for advanced usage. They provide an easy way to customize the file parser and dependency detection. Check the pluggable design document for more information.

--config=[filename]: An external configuration file (see below).

Usage with a configuration file

Depcheck can be used with an rc configuration file. In order to do so, create a .depcheckrc file in your project's package.json folder, and set the CLI keys in YAML, JSON, and JavaScript formats. For example, the CLI arguments --ignores="eslint,babel-*" --skip-missing=true would turn into:

.depcheckrc

ignores: ["eslint", "babel-*"]
skip-missing: true

Important: if provided CLI arguments conflict with configuration file ones, the CLI ones will take precedence over the rc file ones.

The rc configuration file can also contain the following extensions: .json, .yaml, .yml.

API

Similar options are provided to depcheck function for programming:

import depcheck from 'depcheck';

const options = {
  ignoreBinPackage: false, // ignore the packages with bin entry
  skipMissing: false, // skip calculation of missing dependencies
  ignorePatterns: [
    // files matching these patterns will be ignored
    'sandbox',
    'dist',
    'bower_components',
  ],
  ignoreMatches: [
    // ignore dependencies that matches these globs
    'grunt-*',
  ],
  parsers: {
    // the target parsers
    '**/*.js': depcheck.parser.es6,
    '**/*.jsx': depcheck.parser.jsx,
  },
  detectors: [
    // the target detectors
    depcheck.detector.requireCallExpression,
    depcheck.detector.importDeclaration,
  ],
  specials: [
    // the target special parsers
    depcheck.special.eslint,
    depcheck.special.webpack,
  ],
  package: {
    // may specify dependencies instead of parsing package.json
    dependencies: {
      lodash: '^4.17.15',
    },
    devDependencies: {
      eslint: '^6.6.0',
    },
    peerDependencies: {},
    optionalDependencies: {},
  },
};

depcheck('/path/to/your/project', options).then((unused) => {
  console.log(unused.dependencies); // an array containing the unused dependencies
  console.log(unused.devDependencies); // an array containing the unused devDependencies
  console.log(unused.missing); // a lookup containing the dependencies missing in `package.json` and where they are used
  console.log(unused.using); // a lookup indicating each dependency is used by which files
  console.log(unused.invalidFiles); // files that cannot access or parse
  console.log(unused.invalidDirs); // directories that cannot access
});

Example

The following example checks the dependencies under /path/to/my/project folder:

$> depcheck /path/to/my/project
Unused dependencies
* underscore
Unused devDependencies
* jasmine
Missing dependencies
* lodash

It figures out:

  • The dependency underscore is declared in the package.json file, but not used by any code.
  • The devDependency jasmine is declared in the package.json file, but not used by any code.
  • The dependency lodash is used somewhere in the code, but not declared in the package.json file.

Please note that, if a subfolder has a package.json file, it is considered another project and should be checked with another depcheck command.

The following example checks the same project, however, outputs as a JSON blob. Depcheck's JSON output is in one single line for easy pipe and computation. The json command after the pipe is a node.js program to beautify the output.

$> depcheck /path/to/my/project --json | json
{
  "dependencies": [
    "underscore"
  ],
  "devDependencies": [
    "jasmine"
  ],
  "missing": {
    "lodash": [
      "/path/to/my/project/file.using.lodash.js"
    ]
  },
  "using": {
    "react": [
      "/path/to/my/project/file.using.react.jsx",
      "/path/to/my/project/another.file.using.react.jsx"
    ],
    "lodash": [
      "/path/to/my/project/file.using.lodash.js"
    ]
  },
  "invalidFiles": {
    "/path/to/my/project/file.having.syntax.error.js": "SyntaxError: <call stack here>"
  },
  "invalidDirs": {
    "/path/to/my/project/folder/without/permission": "Error: EACCES, <call stack here>"
  }
}
  • The dependencies, devDependencies and missing properties have the same meanings in the previous example.
  • The using property is a lookup indicating each dependency is used by which files.
  • The value of missing and using lookup is an array. It means the dependency may be used by many files.
  • The invalidFiles property contains the files having syntax error or permission error. The value is the error details. However, only one error is stored in the lookup.
  • The invalidDirs property contains the directories having permission error. The value is the error details.

False Alert

Depcheck just walks through all files and tries to find the dependencies according to some predefined rules. However, the predefined rules may not be enough or may even be wrong.

There may be some cases in which a dependency is being used but is reported as unused, or a dependency is not used but is reported as missing. These are false alert situations.

If you find that depcheck is reporting a false alert, please open an issue with the following information to let us know:

  • The output from depcheck --json command. Beautified JSON is better.
  • Which dependencies are considered as false alert?
  • How are you using those dependencies, what do the files look like?

Changelog

We use the GitHub release page to manage changelog.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

MIT License.