Skip to main content

Default Behaviour

By default, Scanner connects to the SCANOSS OSS Knowledge Base API at https://api.osskb.org without requiring any authentication.

Using an API Key

Assign your key to the API_KEY property on a Scanner instance:
// Import as ES6
import { Scanner, ScannerEvents } from "scanoss";

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

const scanner = new Scanner();
scanner.API_KEY = "your-api-key";

// 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]);

Using a Custom API URL

To direct the SDK to a different endpoint, assign the target URL to the API_URL property on a Scanner instance:
// Import as ES6
import { Scanner, ScannerEvents } from "scanoss";

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

const scanner = new Scanner();
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]);