package='widdershins'
if [ `npm list -g | grep -c $package` -eq 0 ]; then
    npm install $package --no-shrinkwrap
fi
alternative including the directory check:
package='widdershins'
if [ `npm list -g | grep -c $package` -eq 0 -o ! -d node_module ]; then
    npm install $package --no-shrinkwrap
fi
Explaination:
- npm list -glists all installed packages
- grep -c $packageprints a count of lines containing $package (which is substituted to 'widdershins' in our case)
- -eqis an equals check, e.g.- $a -eq $breturns true if $a is equal to $b, and false otherwise.
- -dchecks if the given argument is a directory (returns true if it is)
- !is the negation operator, in our case is negates the -d result
- -ois the logical or operator
To sum it up: 
- First code: if the $package is installed, then the -eq result is false and this causes the if statement to be false. If $package is not installed, then the -eq result is true (and the if statement is also true).
- Second code: in addition to description of first code, if node_module is a directory, then the if statement is false. If node_module is not a directory then the if statement is true. And this is independend from the -eq result because of the logical or connection.
This could also help you.