Skip to main content

Node-based Projects

Node Metadata Best Practices

The quality of the SBOMs generated by tools depends on the quality of the metadata provided by each of the modules.

We recommend adopting the following practices.

  • Provide basic metadata for your modules
    At a minimum, specify a name and version in every module’s metadata.
  • Specify the license as an SPDX identifier or expression
    When the content is distributed under a single license, specify that license as an SPDX identifier. When the content is distributed under multiple licenses, specify the license as an SPDX expression.
    For example, to express that content may be consumed under either the Eclipse Public License 2.0 or the GNU Public License 2.0 with the Classpath Exception (EPL-2.0 or GPL-2.0-only with Classpath-exception-2.0), include the following in the package.json file:
    "license" : "EPL-2.0 or GPL-2.0-only with Classpath-exception-2.0"
    
  • Keep your dependencies up-to-date
    Keep your dependencies up-to-date and generate SBOMs regularly to maintain an accurate and comprehensive inventory of your Node package’s components and dependencies.

CycloneDX SBOMs from Node

To generate an SBOM for your Node package, you can use tools specifically designed for this purpose, such as CycloneDX. Here are the general steps to generate an SBOM:

  1. Add the @cyclonedx/cyclonedx-npm module as a development dependency and add an sbom script to your package.json file:
    {
      "devDependencies": {
        "@cyclonedx/cyclonedx-npm": "^1.14.1"
      },
      "scripts": {
        "sbom": "cyclonedx-npm --output-format json --output-file sbom.json"
      }
    }
    

    This command will generate an SBOM in JSON format and save it as sbom.json in the current directory.
  2. Install dependencies by running npm install, or yarn.
  3. Run the following command to generate the SBOM:
    $ npm run sbom