Upgrading NPM to the latest version

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 this?

I tried:

 sudo npm update -g cordova 

And this is also without errors:

 npm install npm-check-updates 

But it does not work.

Thanks!!

+6
source share
3 answers

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

 sudo npm install -g cordova@latest 

To update npm, do the same:

 sudo npm install -g npm@latest 
+1
source

Depending on how they are listed in your package.json , you must edit the versions for each dependency.

example:

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

Installing the version on * installs it in the latest version. Read about version dependencies here http://browsenpm.org/package.json

Once you do this, you can inform NPM of the installation of all project dependents.

$ npm install


Tip : if you do not automatically keep your projects dependent on your .json package, you should. Just add --save to the end of your install request. In this way

$ npm install grunt --save

+1
source

see this article HOW: Upgrade 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 package updates 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 } 
-2
source

Source: https://habr.com/ru/post/976481/


All Articles