NPM logo

Backstage NPM Plugin

Created by Christoph Jerolimov

NPM is the package registry for JavaScript. It powers the way Node apps and web libraries are shared. Most teams already use it to publish, install, and track versions.

The NPM plugin brings that context into Backstage. It adds cards to your entity pages that show the current version, publish date, license, keywords, and links to repos and issue trackers. It also adds a releases view so you can see tags like latest or next at a glance, plus a tab with version history when you need more detail. You get a quick read on what a package is, where its code lives, and how it has moved over time.

It fits common workflows. You can spot outdated services and plan upgrades. You can surface prerelease tags without leaving the portal. You can bring private packages into view too. The plugin supports custom registries such as GitHub Packages or GitLab through a backend so tokens stay on the server. Teams that mirror or proxy registries can point the plugin at those sources and still get the same cards and release data.

Installation Instructions

These instructions apply to self-hosted Backstage only.

Install the frontend plugin in a classic Backstage app

  1. Add the package to your app

    Copy
    yarn workspace app add @backstage-community/plugin-npm
  2. Import the components in packages/app/src/components/catalog/EntityPage.tsx

    Copy
    // after other imports
    import {
      isNpmAvailable,
      EntityNpmInfoCard,
      EntityNpmReleaseOverviewCard,
      EntityNpmReleaseTableCard,
    } from '@backstage-community/plugin-npm';
  3. Show the cards on the entity overview page

    Add this to the overview content after EntityAboutCard

    Copy
    <EntitySwitch>
      <EntitySwitch.Case if={isNpmAvailable}>
        <Grid container item md={6} xs={12}>
          <Grid item md={12}>
            <EntityNpmInfoCard />
          </Grid>
          <Grid item md={12}>
            <EntityNpmReleaseOverviewCard />
          </Grid>
        </Grid>
      </EntitySwitch.Case>
    </EntitySwitch>
  4. Add the releases tab to the entity page

    Add this route in serviceEntityPage and websiteEntityPage after the ci cd case
    Add it in defaultEntityPage between the slash route and the docs route

    Copy
    <EntityLayout.Route
      if={isNpmAvailable}
      path="/npm-releases"
      title="NPM Releases"
    >
      <EntityNpmReleaseTableCard />
    </EntityLayout.Route>

Use the new frontend system alpha

  1. Add the package to your app next workspace

    Copy
    yarn workspace app-next add @backstage-community/plugin-npm
  2. Register the feature in packages/app-next/src/App.tsx or packages/app/src/App.tsx if you run the new system there

    Copy
    import npmPlugin from '@backstage-community/plugin-npm/alpha';
    
    export const app = createApp({
      features: [
        catalogPlugin,
        catalogImportPlugin,
        userSettingsPlugin,
        npmPlugin,
        // other features
      ],
    });

Install the backend plugin new backend system

Required for private packages or for custom registries

  1. Add the backend package

    Copy
    yarn workspace backend add @backstage-community/plugin-npm-backend
  2. Register it in packages/backend/src/index.ts

    Copy
    // inside your backend setup
    backend.add(import('@backstage-community/plugin-npm-backend'));
  3. Optional force the frontend to use the backend for all entities

    Copy
    # app-config.yaml
    npm:
      defaultRegistry: npmjs

Old backend system support

This plugin exposes a new backend system feature. The old backend system is not supported.
For public packages you can run the frontend part only

Configure registries

Default public registry works without extra config for public packages

Copy
# app-config.yaml
npm:
  registries:
    - name: npmjs
      url: https://registry.npmjs.com

Private npmjs with token

Copy
# app-config.yaml
npm:
  registries:
    - name: npmjs
      url: https://registry.npmjs.com
      token: YOUR_TOKEN

Custom registry

Copy
# app-config.yaml
npm:
  registries:
    - name: private-registry
      url: https://your.registry.example.com
      token: YOUR_TOKEN

GitHub registry

Copy
# app-config.yaml
npm:
  registries:
    - name: github
      url: https://npm.pkg.github.com
      token: ghp_your_token

To make the backend handle requests for an entity set a matching registry on the entity

Copy
# catalog-info.yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: a-component
  annotations:
    npm/package: private-package
    npm/registry: npmjs

Add entity annotations

Basic setup

Copy
# catalog-info.yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: react
  annotations:
    npm/package: react

Pick a tag other than latest for the info card

Copy
# catalog-info.yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: react
  annotations:
    npm/package: react
    npm/stable-tag: next

Use a named custom registry from your config

Copy
# catalog-info.yaml
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
  name: react
  annotations:
    npm/package: another-package
    npm/registry: github

Optional sample entities

You can import ready made examples for testing

Copy
# catalog-info.yaml
catalog:
  locations:
    - type: url
      target: https://github.com/backstage/community-plugins/blob/main/workspaces/npm/examples/entities.yaml
      rules:
        - allow: [System, Component]

Changelog

This changelog is produced from commits made to the NPM plugin since a year ago, and based on the code located here. It may not contain information about all commits. Releases and version bumps are intentionally omitted. This changelog is generated by AI.

Features

  • Export translation files #5020 merged 1 month ago
  • Add npm registry option extraRequestHeaders #4602 merged 3 months ago
  • Add translation support with a German locale #3528 merged 6 months ago
  • Use Backstage links in the overview card instead of html links #3527 merged 6 months ago
  • Add backend plugin to fetch data from private registries or npmjs with a token #1812 merged 8 months ago
  • Add support for the new frontend system under the alpha export #2453 merged 9 months ago
  • Create a standalone demo app for the npm plugin #1516 merged 11 months ago
  • Introduce the npm plugin workspace that shows info from npmjs #1485 merged 12 months ago

Bug fixes

  • Show the missing annotation state when npm/package is not set. Avoid errors in the hook #4322 merged 3 months ago
  • Add the missing backend api ref to the alpha export. This restores support for private or alternative registries with the new frontend system #3523 merged 6 months ago
  • Export deprecated card components to keep backward compatibility #1751 merged 11 months ago

Documentation

  • Update docs to install the correct npm plugin backend packages #3825 merged 5 months ago

Dev experience

  • Add a dev command. Use a standalone dev app runner to test npm frontend and backend together #4577 merged 3 months ago
  • Create knip report verification for the npm workspace. Remove unused dependencies #4991 merged 1 month ago
  • Reduce knip false positives with a workspace config #3018 merged 7 months ago

Maintenance

  • Remove unused dev dependencies. Add a script to rebuild knip reports #2436 merged 9 months ago

Dependencies

  • Update to Backstage 1.37.1 #3531 merged 6 months ago
  • Update to Backstage 1.36.1 #3478 merged 6 months ago
  • Update to Backstage 1.35.0 #2613 merged 8 months ago

Breaking changes

  • None

Set up Backstage in minutes with Roadie