npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xpack/update-checker

v1.2.0

Published

Check if a newer version of a npm package is available

Downloads

21

Readme

npm (scoped) license Standard Actions Status GitHub issues GitHub pulls

Check if a newer version of a npm package is available

A Node.js module with a class to check if a more recent version of a npm package is available.

Prerequisites

A recent Node.js (>=10.x), since the ECMAScript 6 class syntax is used.

Easy install

The module is available as @xpack/update-checker from the public repository, use npm to install it inside the module where it is needed:

cd <npm-package-project>
npm install @xpack/update-checker

The module does not provide any executables, and generally there are few reasons to install it globally.

The development repository is available from the GitHub xpack/update-checker-js project.

User info

The module can be included in any application and the class can be used directly or custom class can be derived from it for custom behaviour.

A typical use case is a CLI application.

The logger must have at least the log.warning(), log.info(), log.debug(), and log.trace() methods; a good candidate is a logger derived from @xpack/logger.

Example:

const UpdateChecker = require('@xpack/update-checker').UpdateChecker
const Logger = require('@xpack/logger').Logger

async main(argv) {
  const log = new Logger({
    level: 'info'
  })

  // ... Other initializations.

  // Read in the current package JSON (bring your own function here).
  const package = await readPackageJson()

  // Create the notifier object, tuned to the current package.
  updateChecker = new UpdateChecker({
    log: log,
    packageName: package.name,
    packageVersion: package.version
  })

  await updateChecker.initiateVersionRetrieval()

  // ... Perform the application actual work.

  // Before returning, possibly send a notification to the console.
  await updateChecker.notifyIfUpdateIsAvailable()

  return exitCode
}

The check is not done if one of the foollowing conditions are met:

  • running in a CI environment
  • stdout is not a TTY
  • the process is running as root
  • the program is installed in system locations
  • the NO_NPM_UPDATE_NOTIFIER variable is present in the environment map

These checks are performed by specialised modules, but it is possible to override them by passing boolean properties to the constructor:

  • isCI
  • isTTY
  • isRunningAsRoot
  • isInstalledGlobally
  • isInstalledAsRoot

The valability of the check can also be configured via a property:

  • checkUpdatesIntervalSeconds

Maintainer info

This page documents how to use this module in an user application. For maintainer information, see the separate README-MAINTAINER page.

License

The original content is released under the MIT License, with all rights reserved to Liviu Ionescu.