Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm check and update package if needed

We need to integrate Karma test runner into TeamCity and for that I'd like to give sys-engineers small script (powershell or whatever) that would:

  1. pick up desired version number from some config file (I guess I can put it as a comment right in the karma.conf.js)

  2. check if the defined version of karma runner installed in npm's global repo

  3. if it's not, or the installed version is older than desired: pick up and install right version

  4. run it: karma start .\Scripts-Tests\karma.conf.js --reporters teamcity --single-run

So my real question is: "how can one check in a script, if desired version of package installed?". Should you do the check, or it's safe to just call npm -g install everytime?

I don't want to always check and install the latest available version, because other config values may become incompatible

like image 979
iLemming Avatar asked May 13 '13 15:05

iLemming


People also ask

Can npm detect outdated package?

Description. This command will check the registry to see if any (or, specific) installed packages are currently outdated. By default, only the direct dependencies of the root project and direct dependencies of your configured workspaces are shown. Use --all to find all outdated meta-dependencies as well.

Does npm install update packages?

The npm install installs all modules that are listed on package. json file and their dependencies. npm update updates all packages in the node_modules directory and their dependencies.


1 Answers

To check if any module in a project is 'old':

npm outdated 

'outdated' will check every module defined in package.json and see if there is a newer version in the NPM registry.

For example, say xml2js 0.2.6 (located in node_modules in the current project) is outdated because a newer version exists (0.2.7). You would see:

[email protected] node_modules/xml2js current=0.2.6 

To update all dependencies, if you are confident this is desirable:

npm update 

Or, to update a single dependency such as xml2js:

npm update xml2js 

To update package.json version numbers, append the --save flag:

npm update --save 
like image 185
dublx Avatar answered Oct 28 '22 21:10

dublx