npm package: @hypnosphi/nlf
Description: Find licenses for a node application and its node_module dependencies
Author: Ian Kelly
Latest version: 2.1.1

<!-- @@NLF-IGNORE@@ -->

# Node License Finder (nlf)

[![Version](https://img.shields.io/npm/v/nlf.svg)](https://www.npmjs.com/package/nlf) [![Downloads](https://img.shields.io/npm/dm/nlf.svg)](https://www.npmjs.com/package/nlf)
[![Build Status](https://img.shields.io/travis/iandotkelly/nlf.svg)](https://travis-ci.org/iandotkelly/nlf)
[![Known Vulnerabilities](https://snyk.io/test/github/iandotkelly/nlf/badge.svg?targetFile=package.json)](https://snyk.io/test/github/iandotkelly/nlf?targetFile=package.json)
[![Coveralls](https://img.shields.io/coveralls/iandotkelly/nlf.svg)](https://coveralls.io/r/iandotkelly/nlf)

nlf is a utility for attempting to identify the licenses of modules in a node.js project.

It looks for license information in package.json, readme and license files in the project.  Please note, in many cases
the utility is looking
for standard strings in these files, such as MIT, BSD, Apache, GPL etc - this is not error free, so if you have any
concerns at all about the accuracy of the results, you will need to perform a detailed manual review of the project
and its dependencies, reading all terms of any included or referenced license.

## Use

nlf can be used programmatically, or from the command line.

## Options

- `-c`, `--csv` (Default:false) - output in csv format
- `-d`, `--no-dev` (Default:false) - exclude development dependencies
- `-r`, `--reach` (Default: Infinity) - package depth (reach), 0 is current package.json file only
- `-s`, `--summary off|simple|detail` (Default: simple) - summary information, not available in csv format

### CLI

To install:

```sh
$ npm install -g nlf

```

To use:

```sh
$ cd my-module
$ nlf
```

Example output:
<pre>
archy@0.0.2 [license(s): MIT/X11]
└── package.json:  MIT/X11

commander@0.6.1 [license(s): MIT]
└── readme files: MIT

glob@3.2.3 [license(s): BSD]
├── package.json:  BSD
└── license files: BSD

json-stringify-safe@5.0.0 [license(s): BSD]
├── package.json:  BSD
└── license files: BSD

read-installed@0.2.2 [license(s): BSD]
└── license files: BSD

should@1.2.2 [license(s): MIT]
└── readme files: MIT

LICENSES: BSD, MIT, MIT/X11
</pre>

For output in CSV format use the -c (or --csv) switch:

```sh
$ cd my-module
$ nlf -c
```

To exclude development dependencies and only analyze dependencies for production:

```sh
$ cd my-module
$ nlf -d
```

#### Summary Mode

`--summary <mode>` option, which can be set to "off", "simple" or "detail". This option controls what will be printed in summary in standard format.

* `off` turns off summary output
* `simple` shows a list of licenses used in the project, the default behavior
* `detail` shows all modules in current project and group by licenses. As example below:

```sh
LICENSES:
├─┬ BSD
│ ├── amdefine@1.0.0
│ ├── boom@0.4.2
│ ├── cryptiles@0.2.2
│ └── diff@1.4.0
├─┬ BSD-2-Clause
│ └── normalize-package-data@2.3.5
├─┬ Apache-2.0
│ ├── request@2.40.0
│ ├── spdx-correct@1.0.2
│ └── validate-npm-package-license@3.0.1
├─┬ (MIT AND CC-BY-3.0)
│ └── spdx-expression-parse@1.0.1
└─┬ MPL
  └── tough-cookie@2.2.1
```

### Programmatically

```javascript
var nlf = require('nlf');

nlf.find({ directory: '/User/me/my-project' }, function (err, data) {
	// do something with the response object.
	console.log(JSON.stringify(data));
});

// to only include production dependencies
nlf.find({
	directory: '/User/me/my-project',
	production: true
}, function (err, data) {
	// do something with the response object.
	console.log(JSON.stringify(data));
});

```

The data returned from find() is an array of modules, each of which is represented by an object as the following example:

```
{
  "id": "example@0.2.9",
  "name": "example",
  "version": "0.2.9",
  "repository": "http:\/\/github.com\/iandotkelly\/example",
  "directory": "\/Users\/ian\/example",
  "licenseSources": {
    "package": {
      "sources": [
        {
          "license": "MIT",
          "url": "http://opensource.org/MIT"
        }
      ]
    },
    "license": {
      "sources": [
        {
          "filePath": "\/Users\/ian\/Personal\/example\/LICENSE",
          "text": "the text of the license file",
          "names": function() { // function that returns the name of the license if known }
        }
      ]
    },
    "readme": {
      "sources": [
        {
          "filePath": "\/Users\/ian\/Personal\/example\/readme.md",
          "text": "text of the readme"
          "names": function() { // function that returns the name of the license if known }
        }
      ]
    }
  }
}
```

Each

### Tests

To run the unit tests, install development dependencies and run tests with 'gulp'.  Requires [gulp.js](http://gulpjs.com/) to be installed globally.

```sh
# only need to install gulp if you have not done so already
$ npm install -g gulp
$ cd nlf
$ npm install
$ gulp
```
If you contribute to the project, tests are written in [mocha](http://mochajs.org/), using [should.js](https://github.com/visionmedia/should.js/) or the node.js assert module.