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.
Try following command if you using npm 5 and node 8
npm update --save
If you are using
yarn
,yarn upgrade-interactive
is a really sleek tool that can allow you to view your outdated dependencies and then select which ones you want to update.More reasons to use Yarn over
npm
. Heh.Here is a basic regex to match semantic version numbers so you can quickly replace them all with an asterisk.
Semantic Version Regex
How to use
Select the package versions you want to replace in the JSON file.
Input the regex above and verify it's matching the correct text.
Replace all matches with an asterisk.
Run
npm update --save
The above commands are unsafe because you might break your module when switching versions. Instead I recommend the following
npm shrinkwrap
command.Should get you the latest wanted versions compatible for your app. But not the latest versions.
This is what I did to update all the dependencies in
package.json
to latest: