update-notifier-cjs is a JavaScript library designed to provide non-intrusive update notifications for Command Line Interface (CLI) applications. Currently at version 5.1.7, it is specifically maintained for CommonJS (CJS) environments, providing a direct alternative to `update-notifier` for projects that do not use ES Modules. The library works by asynchronously checking for package updates against the npm registry in a detached child process, ensuring no impact on the CLI tool's startup performance. It persists the check results and displays notifications only after a configurable interval (defaulting to one day), preventing frequent interruptions to the user. This design choice aims to be user-friendly by avoiding immediate notifications on first run or every execution.
npm install update-notifier-cjsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize the update notifier and immediately check for and display update notifications for a CLI application using a simple `package.json` object. This example includes settings to facilitate testing.
For testing, set a very short `updateCheckInterval` (e.g., `1000 * 5` for 5 seconds) and run your CLI application multiple times, or consult the `example.js` provided by the package for testing strategies. Note that `defer: false` in `notify()` options can force immediate display.
Always pass `pkg` derived from your `package.json` file: `const pkg = require('./package.json'); updateNotifier({pkg}).notify();`This is intended behavior for non-intrusive updates. If you need to log update information regardless of TTY status, manually check `notifier.update` and use `console.log()` if an update is available.
To enable notifications in npm scripts, explicitly set `shouldNotifyInNpmScript: true` in the notifier options: `updateNotifier({ pkg, shouldNotifyInNpmScript: true }).notify();`Ensure you are passing a valid `pkg` object, typically by reading your `package.json`: `const pkg = require('./package.json'); updateNotifier({pkg});`For development and testing, temporarily set `updateCheckInterval` to a very low value (e.g., `1000 * 5` for 5 seconds) in the options. Remember to run the application multiple times to trigger the stored notification.
Set `shouldNotifyInNpmScript: true` in the options passed to `updateNotifier`: `updateNotifier({ pkg, shouldNotifyInNpmScript: true }).notify();`This package is strictly CommonJS. Use the `require()` syntax: `const updateNotifier = require('update-notifier-cjs');`. If your project is ESM-only, you might need to consider alternatives or dynamic `import()` if the context allows, though this package is built for CJS.No dependency data recorded yet.