> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scanoss.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage

> The `scanoss` package can be imported directly into JavaScript and TypeScript projects from `scanoss`.

## Scanning with `scanoss.json`

To scan using a `scanoss.json` settings file, load and parse the file, pass it to `ScannerCfg.SCANOSS_SETTINGS`, and configure the `Scanner` with your API key and endpoint before calling `scan()`:

```typescript theme={null}
// Import as ES6
import { Scanner, ScannerCfg, ScannerEvents } from "scanoss";
import { readFileSync } from "fs";

// Import as CommonJS
// const { Scanner, ScannerEvents } = require('scanoss');

const settings = JSON.parse(
  readFileSync("/yourProjectFolder/scanoss.json", "utf-8"),
);

const cfg = new ScannerCfg();
cfg.SCANOSS_SETTINGS = settings; // parsed object, not a file path

const scanner = new Scanner(cfg);
scanner.API_KEY = "your-api-key";
scanner.API_URL = "https://your-custom-api-url";

// Set the folder path where the module will save the scan results and fingerprints
// If is not specified, the module will create a folder on tmp
// directory using a timestamp as a name
scanner.setWorkDirectory("/yourProjectFolder/ScanResults/");

// Set the scanner log event handler
scanner.on(ScannerEvents.SCANNER_LOG, (logTxt) => console.log(logTxt));

// Set the scanner finish event handler
scanner.on(ScannerEvents.SCAN_DONE, (resultPath) => {
  console.log("Path to results: ", resultPath);
});

const scannerInput = {
  fileList: ["/yourProjectFolder/example1.c"],
};

// Launch the scanner
scanner.scan([scannerInput]);
```

## Scanner Events Reference

The `Scanner` class (and `Fingerprint`, which shares the same event system) emits the
following events, which can be subscribed to via `.on()`:

| Event                 | Description                                                              |
| --------------------- | ------------------------------------------------------------------------ |
| `SCAN_DONE`           | Scan completed; provides the path to the results file                    |
| `SCANNER_LOG`         | Internal log messages emitted by the scanner                             |
| `DISPATCHER_NEW_DATA` | New results received from the server; not yet written to the output file |
| `RESULTS_APPENDED`    | Buffered results written and appended to the output file                 |
| `WINNOWING_STATUS`    | Progress update during fingerprint generation                            |
| `ERROR`               | An error occurred during scanning                                        |
