Skip to content

Instantly share code, notes, and snippets.

@toboid
Created June 18, 2017 15:24
Show Gist options
  • Save toboid/f78eb25c8c071086bd1ac3bab4bc3a0b to your computer and use it in GitHub Desktop.
Save toboid/f78eb25c8c071086bd1ac3bab4bc3a0b to your computer and use it in GitHub Desktop.
Use nvm to find which node versions a global module is installed for
nvm_global () {
PKG_NAME=$1
VERSIONS=()
I=0
for VER in $(nvm_ls)
do
nvm exec --silent ${VER} npm ls -g ${PKG_NAME} --depth=0 >/dev/null 2>&1
if [ $? -eq 0 ]; then
VERSIONS[I]=${VER}
fi
let I=${I}+1
done
if [ ${#VERSIONS[@]} -eq 0 ]; then
echo "${PKG_NAME} not found for any node version installed through nvm"
else
echo "Found ${PKG_NAME} for node versions:"
for VERSION in "${VERSIONS[@]}"
do
echo -e "\t${VERSION}"
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment