Check NPM package licenses

Overview

NPM License Checker

Build Status

As of v17.0.0 the failOn and onlyAllow arguments take semicolons as delimeters instead of commas. Some license names contain commas and it messed with the parsing

Ever needed to see all the license info for a module and its dependencies?

It's this easy:

npm install -g license-checker

mkdir foo
cd foo
npm install yui-lint
license-checker

You should see something like this:

├─ [email protected]
│  ├─ repository: http://github.com/chriso/cli
│  └─ licenses: MIT
├─ [email protected]
│  ├─ repository: https://github.com/isaacs/node-glob
│  └─ licenses: UNKNOWN
├─ [email protected]
│  ├─ repository: https://github.com/isaacs/node-graceful-fs
│  └─ licenses: UNKNOWN
├─ [email protected]
│  ├─ repository: https://github.com/isaacs/inherits
│  └─ licenses: UNKNOWN
├─ [email protected]
│  └─ licenses: MIT
├─ [email protected]
│  ├─ repository: https://github.com/isaacs/node-lru-cache
│  └─ licenses: MIT
├─ [email protected]
│  ├─ repository: https://github.com/isaacs/node-lru-cache
│  └─ licenses: MIT
├─ [email protected]
│  ├─ repository: https://github.com/isaacs/minimatch
│  └─ licenses: MIT
├─ [email protected]
│  ├─ repository: https://github.com/isaacs/minimatch
│  └─ licenses: MIT
├─ [email protected]
│  ├─ repository: https://github.com/isaacs/sigmund
│  └─ licenses: UNKNOWN
└─ [email protected]
   ├─ licenses: BSD
      └─ repository: http://github.com/yui/yui-lint

An asterisk next to a license name means that it was deduced from an other file than package.json (README, LICENSE, COPYING, ...) You could see something like this:

└─ [email protected]
   ├─ repository: https://github.com/visionmedia/debug
   └─ licenses: MIT*

Options

  • --production only show production dependencies.
  • --development only show development dependencies.
  • --start [path of the initial json to look for]
  • --unknown report guessed licenses as unknown licenses.
  • --onlyunknown only list packages with unknown or guessed licenses.
  • --json output in json format.
  • --csv output in csv format.
  • --csvComponentPrefix prefix column for component in csv format.
  • --out [filepath] write the data to a specific file.
  • --customPath to add a custom Format file in JSON
  • --exclude [list] exclude modules which licenses are in the comma-separated list from the output
  • --relativeLicensePath output the location of the license files as relative paths
  • --summary output a summary of the license usage',
  • --failOn [list] fail (exit with code 1) on the first occurrence of the licenses of the semicolon-separated list
  • --onlyAllow [list] fail (exit with code 1) on the first occurrence of the licenses not in the semicolon-seperated list
  • --packages [list] restrict output to the packages (package@version) in the semicolon-seperated list
  • --excludePackages [list] restrict output to the packages (package@version) not in the semicolon-seperated list
  • --excludePrivatePackages restrict output to not include any package marked as private
  • --direct look for direct dependencies only

Exclusions

A list of licenses is the simplest way to describe what you want to exclude.

You can use valid SPDX identifiers. You can use valid SPDX expressions like MIT OR X11. You can use non-valid SPDX identifiers, like Public Domain, since npm does support some license strings that are not SPDX identifiers.

Examples

license-checker --json > /path/to/licenses.json
license-checker --csv --out /path/to/licenses.csv
license-checker --unknown
license-checker --customPath customFormatExample.json
license-checker --exclude 'MIT, MIT OR X11, BSD, ISC'
license-checker --packages '[email protected];[email protected];[email protected]'
license-checker --excludePackages 'internal-1;internal-2'
license-checker --onlyunknown

Custom format

The --customPath option can be used with CSV to specify the columns. Note that the first column, module_name, will always be used.

When used with JSON format, it will add the specified items to the usual ones.

The available items are the following:

  • name
  • version
  • description
  • repository
  • publisher
  • email
  • url
  • licenses
  • licenseFile
  • licenseText
  • licenseModified

You can also give default values for each item. See an example in customFormatExample.json.

Requiring

var checker = require('license-checker');

checker.init({
    start: '/path/to/start/looking'
}, function(err, packages) {
    if (err) {
        //Handle error
    } else {
        //The sorted package data
        //as an Object
    }
});

Debugging

license-checker uses debug for internal logging. There’s two internal markers:

  • license-checker:error for errors
  • license-checker:log for non-errors

Set the DEBUG environment variable to one of these to see debug output:

$ export DEBUG=license-checker*; license-checker
scanning ./yui-lint
├─ [email protected]
│  ├─ repository: http://github.com/chriso/cli
│  └─ licenses: MIT
# ...

How Licenses are Found

We walk through the node_modules directory with the read-installed module. Once we gathered a list of modules we walk through them and look at all of their package.json's, We try to identify the license with the spdx module to see if it has a valid SPDX license attached. If that fails, we then look into the module for the following files: LICENSE, LICENCE, COPYING, & README.

If one of the those files are found (in that order) we will attempt to parse the license data from it with a list of known license texts. This will be shown with the * next to the name of the license to show that we "guessed" at it.

Comments
  • Custom format provider

    Custom format provider

    The custom format provider allows you to pick specific attributes from the package.json. Things like name, version or author can be picked nicely and will be drawn accordingly.

    The markdown- and json- functions have been extended to support the custom formats.

    opened by ptusch 14
  • Add depth license checking management

    Add depth license checking management

    Hi,

    Nice to meet you.

    I'm in the process of license validation and your tool was the closest to what I was looking for. It only missed a depth option management.

    Here it is. I leveraged the depth option of read-installed package. It is not perfect because sometimes a npm install may installed dependencies of your direct dependencies at level 0. Anyway, it still allows filtering of node_modules.

    I also documented the start option. Which I would I love to name path.

    opened by hervenivon 9
  • Add option to only show unknown licenses

    Add option to only show unknown licenses

    This could be used for potential license leaks. If you want to know if you have unknown or guessed licenses, you could simply add the '--onlyunknown' tag to only show those packages.

    opened by ptusch 9
  • A lot of packages are marked as UNKNOWN but have a license in the readme

    A lot of packages are marked as UNKNOWN but have a license in the readme

    It looks like a lot of UNKNOWNs have a MIT license in the readme.

    At https://github.com/davglass/license-checker/blob/d7dc3c199636e986b3ba293a67a30bbdfc7bf2b7/lib/index.js#L116-L117 there's a license(json.readme) check.

    json.readme seems to come from var read = require('read-installed'); which doesn't seem to be maintained/updated anymore (https://github.com/npm/read-package-tree is the new one).

    I think there's a bug which results in ERROR: No README data found! for the readme.

    opened by hzoo 8
  • feat: allow restricting output to specified packages

    feat: allow restricting output to specified packages

    Hello everyone and a special hello to @davglass!

    Thanks for this amazing package - it helps me not implement a lot of things i'd otherwise have to implement! 👍

    Until now, restricting the generated output to specific packages (and versions) is not possible. In an environment where a legal department has to check every open source license that is part of a delivered product, the only way to handle this with the current version of license-checker is to scan all dependencies (including devDependencies).

    Using the --production switch is not feasible in this scenario, because especially in frontend applications that are built using tooling such as webpack, parcel, rollup, browserify or others, the tools unfortunately don't care if a dependency that is included in a build artifact was listed as a or derived from a devDependency or a dependency.

    Because the bulk of our builds is done with webpack, i'm implementing a webpack plugin that generates a list of packages and versions that are actually part of a build output and would love to use depend on license-checker to do the heavy-lifting in regards to checking licenses. To do so, i need a way to restrict the license-checker output to specific packages and versions while ignoring the rest.

    Another way to deal with this would be to expose a method that can check the license of a single package, but that would involve a lot of refactoring, dealing with read-installed and more. I've tried it and it did not look & feel well.

    Therefore, i've implemented an additional CLI switch called --packages that accepts a semicolon-separated list of package@version identifiers and restricts the output of license-checker to these packages. The code changes are minimal because all packages read by read-installed are checked and the filtered return value is then restricted to the given packages.

    I'm aware that this is not the most performant solution, but i'm perfectly fine with that because i did not have to introduce a lot of changes and license-checker is pretty fast regardless.

    opened by codepunkt 7
  • whitelist licenses to not fail on

    whitelist licenses to not fail on

    Currently you can only blacklist licenses via -failOn

    However, if you want to be more strict you probably want to explicitly whitelist the licenses which are ok for you.

    Ideas:

    • introduce a negation operator, e.g.: -failOn="!(MIT,Apache)"
    • introduce another flag, e.g.: -notFailOn="MIT,Apache"
    opened by tknerr 7
  • Clarify how license is determined

    Clarify how license is determined

    For some reason license-checked can't figure out the license for uid-number (package.json v0.0.6) and pouchdb-collections (package.json v1.0.1). Even though in both cases they do have a seemingly valid license field in their package.json.

    I've checked with DEBUG=license-checker* and I don't see an error. I'm using license-checker 13.0.2, I've checked the package.json's of the versions I'm using (checking package-lock.json)

    Could a little bit of documentation be added on how license-checker determines the license?

    opened by peteruithoven 7
  • JSON uses single quotes instead of double quotes, and therefore isn't valid JSON

    JSON uses single quotes instead of double quotes, and therefore isn't valid JSON

    Hello,

    It looks like when running license-checker with the --json flag, the JSON that's generated uses single quotes instead of double quotes, which means that parsing it with JSON.parse() fails.

    opened by Bosch-Eli-Black 6
  • Combine with webpack to list only really imported packages

    Combine with webpack to list only really imported packages

    I wonder how this could be combined with webpack (as a preloader?) to only really gather information about packages that are imported or required by the app.

    opened by pke 6
  • Feature Request: List licenses for dependencies, only

    Feature Request: List licenses for dependencies, only

    I would like to suggest a new option to list licenses for dependencies, only. In other words, the license for the module defined by package.json itself shall be excluded. Assuming this can be controlled by a command line option "--dependencies" this can be achieved easily by the following patch.

    https://github.com/mwittig/license-checker/commit/01cde66943beb1c403c880fe8e001f90ca75526f

    Of course, some additional code will be required to set the command line option. I am happy to do that if the feature request finds your acceptance. Please also advise further about test requirements in case.

    opened by mwittig 6
  • Option to list licenses only for dependencies in package.json

    Option to list licenses only for dependencies in package.json

    I would like an option to list licenses for "first" dependencies in the dependency tree. So in other words list dependencies only for the modules which are listed in package.json file's "dependencies".

    opened by kimmobrunfeldt 6
  • Bug: Treatment of UNLICENSED when package not private

    Bug: Treatment of UNLICENSED when package not private

    We have a monorepo and publish private packages from it to NPM to be consumed by our applications.

    The config for a package includes:

    "name": "@example/packageName",
    "license": "UNLICENSED",
    "publishConfig": {
        "access": "restricted"
    },
    

    Packages marked as private: true are not published to the registry, so packages publishing private packages to NPM cannot use this.

    From the NPM docs.

    private

    If you set "private": true in your package.json, then npm will refuse to publish it.

    This is a way to prevent accidental publication of private repositories. If you would like to ensure that a given package is only ever published to a specific registry (for example, an internal registry), then use the publishConfig dictionary described below to override the registry config param at publish-time.

    Inside apps that consume our packages we are running license-checker. Instead of reporting our packages as UNLICENSED, it reports them as UNKNOWN. This is because if the value of package's license field is UNKNOWN a value of null is returned from license. There is a subsequent check for UNLICENCED, but it only happens for packages that have private: true.

    It is perfectly valid to have a license of UNLICENSED for a non-private package when published and consumed in this way so this feels like a bug.

    opened by Undistraction 1
  • Update to mkdirp v 1.x.x

    Update to mkdirp v 1.x.x

    Hi , Mkdrip (v0.5.x) needs "minimist" which is a High Security Issue in Whitesource . Mkdirp is now already getting 1.0.4 which totally exclude the "Minimist" Module. Could you guys please update to this newer Major Version of mkdirp ?

    Thanks in advance

    opened by onecib 0
  • License not recognized due to casing

    License not recognized due to casing

    The package cluster-key-slot1.1.0 specifies the non-standard license name APACHE-2.0, see https://github.com/invertase/cluster-key-slot/blob/v1.1.0/package.json. This gets recognizes as Apache*. To reproduce: npx license-checker --packages '[email protected]' It could be recognized as Apache-2.0 if only the casing differs.

    opened by Treiblesschorle 0
  • highcharts license incorrectly reported using highcharts-server license URL

    highcharts license incorrectly reported using highcharts-server license URL

    package.json file:

    {
      "dependencies": {
        "react-highcharts": "^16.1.0"
      }
    }
    

    Run

    npm i
    license-checker --packages "[email protected]"
    

    Output:

    └─ [email protected]
       ├─ licenses: Custom: https://www.npmjs.com/package/highcharts-server
    ...
    

    However, node_modules/highcharts/package.json has this:

    "license": "https://www.highcharts.com/license"
    

    The difference is significant, because highcharts-server is MIT-licensed, while highcharts has a commercial license.

    opened by loop-evgeny 1
Owner
Dav Glass
Currently taking a much needed sabbatical from Open Source and technology, please respect. Former Yahoo/Verizon Open Source guy. I'm also the creator of @HackSI
Dav Glass
Check ipo allotment result from CLI. [WIP for bulk check]

# Check your ipo allotment result via CLI Install node js and run these commands > clone the repo > cd checkipo-cli > npm

Yaman Sarabariya 4 Oct 12, 2022
:eyeglasses: Node.js module that tells you when your package npm dependencies are out of date.

Node.js module that tells you when your package npm dependencies are out of date. Getting Started Install Node.js. Install david: cd /your/project/dir

Alan Shaw 953 Dec 25, 2022
Open the npm page, Yarn page, or GitHub repo of a package

npm-home Open the npm page, Yarn page, or GitHub repo of a package Install $ npm install --global npm-home Usage $ npm-home --help Usage $ npm

Sindre Sorhus 180 Dec 18, 2022
Package manager faster than NPM

Pine Script holder that runs faster than NPM and yarn Pine is a npm and yarn run like module, that allows you to organize your scripts and run them FA

Darkling 4 Jul 10, 2021
Check if the internet connection is up

is-online Check if the internet connection is up Works in Node.js and the browser (with a bundler). In the browser you have navigator.onLine, but it's

Sindre Sorhus 1.1k Jan 1, 2023
Check whether a website is up or down

is-up Check whether a website is up or down using the isitup.org API Install $ npm install is-up Usage const isUp = require('is-up'); (async () => {

Sindre Sorhus 384 Dec 7, 2022
NodeJS built CLI, allows to spell check in 14 languages, get Coleman-Liau Index and build hash Pyramids

Magic CLI ?? ?? NodeJS built CLI, allows to spell check in 14 languages, get Coleman-Liau Index and build hash Pyramids Installing Install dependencie

Lucas 3 Sep 27, 2022
A better `npm publish`

np A better npm publish Why Interactive UI Ensures you are publishing from your release branch (main and master by default) Ensures the working direct

Sindre Sorhus 6.9k Jan 2, 2023
Uses marked-terminal to render a README.md for any npm module in the terminal.

modhelp Uses marked-terminal to render a README.md for any npm module in the terminal. Now with built-in pager! Page up/down, arrow keys to scroll lin

Jason Livesay 23 Feb 8, 2022
Add a hungry turtle to your terminal and feed it every time you mistype 'npm' as 'nom'

Nom Does this ever happen to you? You happily code away on a project, navigating the command line like a pro, testing, error logging, installing packa

Meike Hankewicz 5 Apr 26, 2022
An npm module to run Snowflake in a headless browser to help censored users connect to the Tor network.

snowflake-cli An npm module to run Snowflake in a headless browser to help censored users connect to the Tor network. Note: depending on your environm

yan 8 Mar 24, 2022
Translations with speech synthesis in your terminal as a node package

Normit Normit is an easy way to translate stuff in your terminal. You can check out its Ruby gem version termit. Installation npm install normit -g Us

Paweł Urbanek 234 Jan 1, 2023
Node.js CLI tool to visualize an aggregate list of your dependencies' licenses

licenseye Node.js CLI tool to visualize an aggregate list of your project's dependencies' licenses. Install Yarn yarn global add licenseye NPM npm ins

Liran Tal 36 Dec 21, 2022
Check in, check the weather, Check out.

☀️ Just-Weather ??️ Hi, Welcome! Just Weather is a Web App designed for Fast Real-Time Weather queries in combination with well Thought Out Visual Des

Miguel Ángel 6 Aug 7, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
npm i uuid, npm i nodemon, npm i commander

goit-nodejs-hw-01 Получаем и выводим весь список контактов в виде таблицы (console.table) node index.js --action list Получаем контакт по id node inde

Oksana Banshchykova 3 Jul 5, 2022
Check whether a package or organization name is available on npm

npm-name Check whether a package or organization name is available on npm Install $ npm install npm-name Usage import npmName from 'npm-name'; // Ch

Sindre Sorhus 157 Nov 13, 2022
An NPM package to help frontend developers get started with using SASS and SCSS on your project easily. The Package follows the 7-1 architecture project structure.

Project Title - Create SASS APP Ever wanted to code up a frontend project with SASS & SCSS and you are stuck with building the acclaimed 7-1 architect

Kelechi Okoronkwo 7 Sep 22, 2022
Check ipo allotment result from CLI. [WIP for bulk check]

# Check your ipo allotment result via CLI Install node js and run these commands > clone the repo > cd checkipo-cli > npm

Yaman Sarabariya 4 Oct 12, 2022
A mobile web application to check the data on the total covid19 confirmed cases and deaths, check data for all countries with recorded cases.

This is a mobile web application to check the data on the total covid19 confirmed cases and deaths, check data for all countries with recorded cases. It also has a details page to check for the statistics for each region/state if available.

Solomon Hagan 7 Jul 30, 2022