Socket
Socket
Sign inDemoInstall

update-check

Package Overview
Dependencies
8
Maintainers
6
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    update-check

Minimalistic update notifications for command line interfaces


Version published
Weekly downloads
1.8M
increased by1.46%
Maintainers
6
Install size
201 kB
Created
Weekly downloads
 

Package description

What is update-check?

The update-check npm package is used to check for updates of a particular package. It is typically used in command-line applications to inform users when a new version of the application is available. The package provides a simple API to check a registry (like npm) for published updates.

What are update-check's main functionalities?

Check for updates

This feature allows you to check if there is an update available for a given package. You provide the current package name and version, and it returns an object with the latest version if an update is available.

const updateCheck = require('update-check');

(async () => {
  let update = await updateCheck({name: 'your-package-name', version: 'current-version'});
  if (update) {
    console.log(`Update available: ${update.latest}`);
  }
})();

Custom registry

This feature allows you to specify a custom registry URL to check for updates, which can be useful if you are using a private registry or a registry other than npm.

const updateCheck = require('update-check');

(async () => {
  let update = await updateCheck({name: 'your-package-name', version: 'current-version'}, {registryUrl: 'https://custom-registry.com'});
  if (update) {
    console.log(`Update available from custom registry: ${update.latest}`);
  }
})();

Dist-tag

This feature allows you to check for updates under a specific distribution tag. This is useful when you want to check for updates that are not necessarily the 'latest' according to semver, but are tagged differently, like 'beta' or 'next'.

const updateCheck = require('update-check');

(async () => {
  let update = await updateCheck({name: 'your-package-name', version: 'current-version', distTag: 'next'});
  if (update) {
    console.log(`Update available on dist-tag 'next': ${update.latest}`);
  }
})();

Other packages similar to update-check

Readme

Source

update-check

npm version install size

This is a very minimal approach to update checking for globally installed packages.

Because it's so simple, the error surface is very tiny and your user's are guaranteed to receive the update message if there's a new version.

You can read more about the reasoning behind this project here.

Usage

Firstly, install the package with yarn...

yarn add update-check

...or npm:

npm install update-check

Next, initialize it.

If there's a new update available, the package will return the content of latest version's package.json file:

const pkg = require('./package');
const checkForUpdate = require('update-check');

let update = null;

try {
	update = await checkForUpdate(pkg);
} catch (err) {
	console.error(`Failed to check for updates: ${err}`);
}

if (update) {
	console.log(`The latest version is ${update.latest}. Please update!`);
}

That's it! You're done.

Configuration

If you want, you can also pass options to customize the package's behavior:

const pkg = require('./package');
const checkForUpdate = require('update-check');

let update = null;

try {
	update = await checkForUpdate(pkg, {
		interval: 3600000,  // For how long to cache latest version (default: 1 day)
		distTag: 'canary'   // A npm distribution tag for comparision (default: 'latest')
	});
} catch (err) {
	console.error(`Failed to check for updates: ${err}`);
}

if (update) {
	console.log(`The latest version is ${update.latest}. Please update!`);
}

Contributing

  1. Fork this repository to your own GitHub account and then clone it to your local device
  2. Link the package to the global module directory: npm link
  3. Within the module you want to test your local development instance of the package, just link it: npm link update-check. Instead of the default one from npm, node will now use your clone.

Author

Leo Lamprecht (@notquiteleo) - ZEIT

Keywords

FAQs

Last updated on 13 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc