Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if npm module installed in bash

Tags:

bash

npm

My objective is to only install this npm package if it's not already available. This continues to to execute even when I've installed the module globally.

if [ npm list -g widdershins &> /dev/null ] || [ ! -d node_modules ]; then
    npm install widdershins --no-shrinkwrap
fi

How can I adjust this to detect when it's installed globally?

like image 342
Webnet Avatar asked Nov 30 '22 14:11

Webnet


1 Answers

if you want a one liner:

Local

npm list | grep widdershins || npm install widdershins --no-shrinkwrap

Global:

npm list -g | grep widdershins || npm install -g widdershins --no-shrinkwrap
like image 87
OZZIE Avatar answered Dec 04 '22 04:12

OZZIE