javascript tutorial - [5 Solutions] Update each dependency in package.json - javascript - java script - javascript array
Problem:
How to update each dependency in package.json to the latest version ?
Solution 1:
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"
}
}
click below button to copy the code. By JavaScript tutorial team
Solution 2:
Looks like npm-check-updates is the only way to make this happen now.
npm i -g npm-check-updates
npm-check-updates -u
npm install
click below button to copy the code. By JavaScript tutorial team
On npm <3.11: Simply change every dependency's version to *, then run npm update --save.
Before:
"dependencies": {
"express": "*",
"mongodb": "*",
"underscore": "*",
"rjs": "*",
"jade": "*",
"async": "*"
}
click below button to copy the code. By JavaScript tutorial team
After:
"dependencies": {
"express": "~3.2.0",
"mongodb": "~1.2.14",
"underscore": "~1.4.4",
"rjs": "~2.10.0",
"jade": "~0.29.0",
"async": "~0.2.7"
}
click below button to copy the code. By JavaScript tutorial team
Solution 3:
npm-check-updates is a utility that automatically adjusts a package.json with the latest version of all dependencies
$ npm install -g npm-check-updates
$ npm-check-updates -u
$ npm install
click below button to copy the code. By JavaScript tutorial team
Solution 4:
To update one dependency to its lastest version without having to manually open the package.json
and change it, you can run
npm install {package-name}@* {save flags?}
click below button to copy the code. By JavaScript tutorial team
i.e;
npm install express@* --save
click below button to copy the code. By JavaScript tutorial team
Solution 5:
- Use * as the version for the latest releases, including unstable
- Use latest as version definition for the latest stable version
- Modify the package.json with exactly the latest stable version number using LatestStablePackages
Here is an example:
"dependencies": {
"express": "latest" // using the latest STABLE version
, "node-gyp": "latest"
, "jade": "latest"
, "mongoose": "*" // using the newest version, may involve the unstable releases
, "cookie-parser": "latest"
, "express-session": "latest"
, "body-parser": "latest"
, "nodemailer":"latest"
, "validator": "latest"
, "bcrypt": "latest"
, "formidable": "latest"
, "path": "latest"
, "fs-extra": "latest"
, "moment": "latest"
, "express-device": "latest"
},