Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to install npm package only if it has not been already installed?

Is it possible to install npm package only if it has not been already installed?

I need this to speed up test on CircleCI, but when I run npm install [email protected] etc. it always downloads things and installs them from scracth, however, node_modules folder with all modules is already present at the moment of running commands (cached from previous build) and protractor --version etc. shows the needed version of the package.

Its perfect to have some one-line command like this:

protractor --version || npm install -g [email protected] 

but the one that will also check version of the package.

like image 404
kovpack Avatar asked Jun 05 '15 13:06

kovpack


People also ask

Does npm install already installed packages?

it always downloads things and installs them from scracth, however, node_modules folder with all modules is already present at the moment of running commands (cached from previous build) and protractor --version etc.

Can I install npm packages offline?

Yes, but simply copying the content of node_modules should be enought, unless you install globally. Another way that may be simpler is to run npm install angular-cli on a connected system, and copy the content of node_modules to the offline computer.

Do I need to download npm for every project?

1 Answer. Show activity on this post. NPM is extremely useful, but, when you install it, you install it globally. It comes with Node JS, so when you install Node JS, you should have npm installed(type npm -v to see the version and whether npm is installed).


1 Answers

You could try npm list protractor || npm install [email protected]

Where npm list protractor is used to find protractor package.

If the package is not found, it will return npm ERR! code 1 and do npm install [email protected] for installation

like image 69
An Nguyen Avatar answered Sep 30 '22 08:09

An Nguyen