node.jsnpm

Output all licenses of installed node.js libraries


Is there an option in npm (or other tool) to print all used licenses? I have a project and I want to make sure I don't use a library which is under a license I can't use.

EDIT: Found out that many developers don't include the license in the package.json, so I had to find out manually using "npm docs package-name"


Solution

  • cd {project}/node_modules
    ls | sed 's/$/\/package.json/' | xargs grep '"license[s]*"' -A 3
    

    Could use some improvement, but it works (at least on osx, should work on linux, no idea about windows). You should see something like:

    grunt/package.json:  "licenses": [
    grunt/package.json-    {
    grunt/package.json-      "type": "MIT",
    grunt/package.json-      "url": "http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT"
    --
    grunt-contrib-concat/package.json:  "licenses": [
    grunt-contrib-concat/package.json-    {
    grunt-contrib-concat/package.json-      "type": "MIT",
    grunt-contrib-concat/package.json-      "url": "https://github.com/gruntjs/grunt-contrib-concat/blob/master/LICENSE-MIT"
    --
    

    Update:

    If you wish to see the name of all modules, even those nested inside other modules, the following works (cred to @robertklep, slightly modified to still work when inside the node_modules directory):

    find * -name package.json | xargs grep '"license[s]*"' -A 3