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

npm-compat

v1.0.1

Published

Gives you latest version of a module compatible with your current Node version

Downloads

8

Readme

npm-compat

npm-compat <package> will give you latest version of <package> that is compatible with your current node version.

Example

Imagine an authour has released a new version of his module, based on Node 0.10, because – for example – it uses the new Stream API. But you're stuck with Node 0.8 :(

npm will be a bit silly on this one, npm install the-package will install latest version of the module (which is incompatible with your version of Node) but shout:

npm WARN engine [email protected]: wanted: {"node":">=0.9.4"} (current: {"node":"v0.8.17","npm":"1.2.0"})

You could list "engines.node" constraints for all versions available, and decide which one you should use:

$ for v in `npm show test-node-version versions | sed 's/^\[\(.*\)\]$/\1/' | sed "s/[',]//g"`; do echo $v: `npm -q show test-node-version@$v engines.node`; done
0.0.0: >0.7
1.0.0: >0.8
1.1.0: >0.8 # Ah! this is the one!!
2.0.0: >=0.9.4
2.1.0: >=0.9.4

Or you could use npm-compat:

$ npm-compat the-package
1.1.0

Installation

$ npm install -g npm-compat

Usage

npm-compat <package-name> [max-version]

Will exit wit code 254 if no compatible version is found, or echo the highest version found that is compatible with your version of Node and lesser than "max-version" if provided.

Typical usage when installing

npm-compat is best used when you face the infamous WARN engine, in that case you should run:

$ npm install --save the-package@`npm-compat the-package`

Extra: shell function

Add this to your .bashrc, .zshrc or whatever:

npm_install_compat() {
  for pkg in $*; do
    local pkgname=`echo "$pkg" | cut -d '@' -f 1`
    local pkgversion=`echo "$pkg" | cut -d '@' -f 2`
    if [ "$pkgversion" = "$pkgname" ]; then
      pkgversion=""
    fi
    npm install --save $pkgname@`npm-compat $pkgname $pkgversion`
  done
}

You can then npm_install_compat module to install latest compatible version of module.

npm_install_compat module1 [email protected]

# equivalent to
npm install --save module1@`npm-compat module1`
npm install --save module2@`npm-compat module2 1.x`