Skip to main content

Prerequisites

Before you begin, ensure you have:

Installation

npm install scanoss

Import Styles

The package supports both ES module and CommonJS import styles:
// ES module
import { Scanner, ScannerEvents, ScannerCfg } from "scanoss";
// CommonJS
const { Scanner, ScannerEvents, ScannerCfg } = require("scanoss");

Quick Start

The following example runs a scan using the default SCANOSS configuration:
// Import as ES6
import { Scanner, ScannerEvents } from "scanoss";

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

const scanner = new Scanner();

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