Simple check for npm package updates.
A lightweight alternative for update-notifier with most of the essential features. Useful for CLI apps.
npm i tiny-update-notifier
import updateNotifier from 'tiny-update-notifier';
import packageJson from './package.json' assert { type: 'json' };
try {
const update = await updateNotifier({ pkg: packageJson });
if (update) {
console.log(`New version of ${update.name} available!`);
console.log(`Update: ${update.current} → ${update.latest} (${update.type})`);
}
} catch {
console.log('Couldn\'t get the latest version.');
}
Check for updates for an npm module.
Returns: Update | false
Contains information about update version etc.
Type: Object
For example:
{ name: 'test', current: '1.0.0', latest: '3.3.0', type: 'major' }
The name of an npm module.
Type: String
Current version of an npm module.
Type: String
Latest version of an npm module.
Type: String
Difference type between current and latest semver version.
Type: String
Possible values:
'major'
'premajor'
'minor'
'preminor'
'patch'
'prepatch'
'prerelease'
Type: Object
Options for getting new update.
Type: object
(required)
Name of npm module.
Type: String
(required)
Version of npm module.
Type: String
(required)
Which dist-tag to use to find the latest version.
Type: String
Default: 'latest'
How often to check for updates.
Type: Number
Default: 1000 * 60 * 60 * 24
(1 day)
Whether to use cache. Setting this option to false
will cause checkInterval
to not function, thus checking for new update every run.
Type: Boolean
Default: true
Maximum time in milliseconds to wait for the request to npm registry to complete.
Type: Number
Default: 30000
(30 seconds)
MIT 💖