CLI Update Notifier

7.3.1 · active · verified Wed Apr 22

update-notifier is a utility package designed to provide non-intrusive update notifications for command-line interface (CLI) applications. Its current stable version is 7.3.1. The package maintains an active release cadence, with several patch and minor updates between major versions, which typically occur every one to two years. A key differentiator is its asynchronous update check mechanism: it performs checks in an unref'ed child process in the background, minimizing impact on the CLI app's startup performance. It also defers initial notifications and subsequent checks based on a configurable `updateCheckInterval`, preventing annoyance and ensuring a smooth user experience. Since v7.0.0, it mandates Node.js 18 or higher, and v6.0.0 transitioned it to a pure ESM package, requiring modern JavaScript module handling. This design philosophy aims to keep CLI tools fresh for users without disrupting their workflow or the developer's application startup speed.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `update-notifier`, access update information, and trigger the notification process in a non-blocking way for a CLI application. It sets a short update check interval for easy testing.

import updateNotifier from 'update-notifier';

// In a real CLI, you'd load your package.json dynamically.
// For demonstration, we'll define a basic package object.
const packageDetails = {
    name: 'my-awesome-cli',
    version: '1.0.0'
};

// Initialize the notifier with a short interval for testing purposes
const notifier = updateNotifier({
    pkg: packageDetails,
    updateCheckInterval: 1000 * 10 // Check every 10 seconds for testing
});

// If there's an update, notify the user.
// The notification is typically deferred until the process exits to avoid disrupting the CLI.
notifier.notify({
    defer: true // Default is true, ensures non-blocking behavior
});

// You can also access update information directly
if (notifier.update) {
    console.log(`An update is available for ${notifier.update.name}: ${notifier.update.current} -> ${notifier.update.latest} (${notifier.update.type})`);
} else {
    console.log(`Your CLI (${packageDetails.name} v${packageDetails.version}) is up to date or update check is pending.`);
}

console.log(`\n${packageDetails.name} CLI is now running its main logic...`);

// Simulate a long-running CLI process
setTimeout(() => {
    console.log('CLI finished its operations.');
    // In a real app, ensure process.exit() is called if necessary,
    // but update-notifier works in a detached process, so it won't prevent exit.
}, 3000);

view raw JSON →