node package manager



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


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 the-package@x.y.z: 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


$ npm install -g npm-compat


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
    npm install --save $pkgname@`npm-compat $pkgname $pkgversion`

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

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