I copied package.json from another project and now want to bump all of the dependencies to their latest versions since this is a fresh project and I don't mind fixing something if it breaks.
What's the easiest way to do this?
The best way I know of now is to run npm info express version
then update package.json manually for each one. There must be a better way.
{
"name": "myproject",
"description": "my node project",
"version": "1.0.0",
"engines": {
"node": "0.8.4",
"npm": "1.1.65"
},
"private": true,
"dependencies": {
"express": "~3.0.3", // how do I get these bumped to latest?
"mongodb": "~1.2.5",
"underscore": "~1.4.2",
"rjs": "~2.9.0",
"jade": "~0.27.2",
"async": "~0.1.22"
}
}
I am now a collaborator on npm-check-updates, which is a great solution to this problem.
If you use yarn, the following command updates all packages to their latest version:
yarn upgrade --latest
From their docs:
Looks like npm-check-updates is the only way to make this happen now.
On npm <3.11:
Simply change every dependency's version to
*
, then runnpm update --save
. (Note: broken in recent (3.11) versions of npm).Before:
After:
Of course, this is the blunt hammer of updating dependencies. It's fine if—as you said—the project is empty and nothing can break.
On the other hand, if you're working in a more mature project, you probably want to verify that there are no breaking changes in your dependencies before upgrading.
To see which modules are outdated, just run
npm outdated
. It will list any installed dependencies that have newer versions available.Greenkeeper if you're using Github. https://greenkeeper.io/
It's a Github integration and incredibly easy to set things up. When installed, it automatically creates pull requests in repositories you specify (or all if wanted) and keeps your code always up-to-date, without forcing you to do anything manually. PRs should then trigger a build on a CI service and depending on a successful or failed check you can keep figuring out what's triggering the issue or when CI passes simply merge the PR.
At the bottom, you can see that the first build failed at first and after a commit ("upgrade to node v6.9") the tests pass so I could finally merge the PR. Comes with a lot of emoji, too.
Another alternative would be https://dependencyci.com/, however I didn't test it intensively. After a first look Greenkeeper looks better in general IMO and has better integration.
I recently had to update several projects that were using npm and package.json for their gruntfile.js magic. The following bash command (multiline command) worked well for me:
The idea here: To pipe the
npm outdated
output as json, tojq
(jq is a json command line parser/query tool)
(notice the use of
--depth
argument fornpm outdated
)jq will strip the output down to just the top level package name only.
finally xargs puts each LIBRARYNAME one at a time into a
npm install LIBRARYNAME --save-dev
commandThe above is what worked for me on a machine runnning: node=v0.11.10 osx=10.9.2 npm=1.3.24
this required:
xargs http://en.wikipedia.org/wiki/Xargs (native to my machine I believe)
and
jq http://stedolan.github.io/jq/ (I installed it with
brew install jq
)Note: I only save the updated libraries to package.json inside of the json key
devDependancies
by using--save-dev
, that was a requirement of my projects, quite possible not yours.Afterward I check that everything is gravy with a simple
Also, you can check the current toplevel installed library versions with
I use
npm-check
to archive this.Another useful command list which will keep exact version numbers in
package.json
If you happen to be using Visual Studio Code as your IDE, this is a fun little extension to make updating
package.json
a one click process.Version Lense