17

I want to update all my packages to the latest version:

npm outdated

Result:

Package                Current        Wanted        Latest  Location
cordova            3.4.0-0.1.0  3.6.3-0.2.13  3.6.3-0.2.13  cordova
commander                2.0.0         2.0.0         2.3.0  npm-check-updates > commander
async                   0.2.10        0.2.10         0.9.0  npm-check-updates > async
semver                   2.2.1         2.2.1         4.0.3  npm-check-updates > semver
read-package-json        1.1.9         1.1.9         1.2.7  npm-check-updates > read-package-json
npm                     1.3.26        1.3.26         2.1.2  npm-check-updates > npm

How can I do that?

I tried it:

sudo npm update -g cordova

And this too with no errors:

npm install npm-check-updates

But it's not working.

Thanks!!

chemitaxis
  • 11,583
  • 14
  • 62
  • 117

3 Answers3

4

npm can! For example, we will update cordova to the latest version:

sudo npm install -g cordova@latest

To update npm, just do the same:

sudo npm install -g npm@latest
Laurent
  • 469
  • 5
  • 15
2

Depending on how they are listed in your package.json you should edit the versions on each dependancy.

an example would be:

"devDependencies": {
  "grunt": "*"
}

Setting the version to * sets it to the latest version. Read about versioning dependancies here http://browsenpm.org/package.json

Once you have done that you can then tell NPM to install all the projects dependents.

$ npm install


Tip: if you are not automatically saving your projects dependants to your package.json, you should. Just add --save to the end of your install query. Like so

$ npm install grunt --save

Ed Knowles
  • 1,805
  • 14
  • 22
1

see this article HOW TO: Update all npm packages in your project at once

“scripts”: {   “update:packages”: “node wipe-dependencies.js &&
                  rm -rf node_modules && npm update --save-dev
                  && npm update --save” },

To run this on the command line:

npm run update:packages

OR only update packages in the npm registry:

const fs = require('fs')
const wipeDependencies = () => {
  const file  = fs.readFileSync('package.json')
  const content = JSON.parse(file)
  for (var devDep in content.devDependencies) {
    if (!content.devDependencies[devDep].includes(git)) {
      content.devDependencies[devDep] = '*'
    }
  }
  for (var dep in content.dependencies) {
    if (!content.dependencies[dep].includes(git)) {
      content.dependencies[dep] = '*'
    }
  }
  fs.writeFileSync('package.json', JSON.stringify(content))
}

if (require.main === module) {
  wipeDependencies()
} else {
  module.exports = wipeDependencies
}
InLaw
  • 2,026
  • 2
  • 16
  • 28