CLI Update Notifier

2.0.0 · active · verified Wed Apr 22

simple-update-notifier is a lightweight and straightforward utility designed to inform users of command-line interface (CLI) applications about available updates on npm. It works by checking the npm registry for newer versions of a specified package and, if an update is found, prints a non-intrusive notification to the terminal. The library is currently at version 2.0.0, released in June 2023, and maintains a fairly active release cadence with minor and patch updates for dependency management and minor enhancements, and less frequent major releases for breaking changes. A key differentiator is its simplicity and built-in caching mechanism, which prevents excessive API calls to npm by only checking for updates at a configurable interval (defaulting to once a day). It also includes options to control notification behavior in npm scripts and specify different npm `dist-tags`.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `simple-update-notifier` into a CLI application. It shows importing the notifier and passing a `pkg` object (typically from `package.json`) along with optional configuration like `updateCheckInterval` and `shouldNotifyInNpmScript`.

import updateNotifier from 'simple-update-notifier';
import packageJson from './package.json' assert { type: 'json' };

// In a real CLI application, this would typically be called once at startup.
// To demonstrate, we'll create a dummy package.json object if not found.
const pkgInfo = packageJson || {
  name: 'my-cli-app',
  version: '1.0.0',
};

async function main() {
  console.log('Running CLI app...');
  await updateNotifier({
    pkg: pkgInfo,
    updateCheckInterval: 1000 * 60 * 60, // Check hourly for demo purposes
    shouldNotifyInNpmScript: true, // Allow notifications in npm scripts for testing
    debug: process.env.DEBUG_UPDATE_NOTIFIER === 'true', // Enable debug logging with env var
  });
  console.log('CLI app finished.');
}

main();

view raw JSON →