How To Install Packages In Package Json
When you lot install a package using npm install <packagename>, the latest available version of the bundle is downloaded and put in the node_modules folder, and a corresponding entry is added to the package.json and package-lock.json files that are nowadays in your current folder.
npm calculates the dependencies and installs the latest available version of those as well.
Let'due south say yous install cowsay, a cool control line tool that lets you make a cow say things.
When y'all npm install cowsay, this entry is added to the packet.json file:
JSON
{
"dependencies" : {
"cowsay" : "^i.iii.ane"
}
}
and this is an extract of package-lock.json, where we removed the nested dependencies for clarity:
JSON
{
"requires" : truthful ,
"lockfileVersion" : i ,
"dependencies" : {
"cowsay" : {
"version" : "1.3.ane" ,
"resolved" : "https://registry.npmjs.org/cowsay/-/cowsay-1.3.1.tgz" ,
"integrity" : "sha512-3PVFe6FePVtPj1HTeLin9v8WyLl+VmM1l1H/5P+BTTDkMAjufp+0F9eLjzRnOHzVAYeIYFF5po5NjRrgefnRMQ==" ,
"requires" : {
"go-stdin" : "^v.0.1" ,
"optimist" : "~0.half dozen.1" ,
"string-width" : "~two.1.1" ,
"strip-eof" : "^1.0.0"
}
}
}
}
Now those 2 files tell us that we installed version ane.3.1 of cowsay, and our rule for updates is ^ane.3.i, which for the npm versioning rules means that npm can update to patch and minor releases: i.iii.ii, one.4.0 and so on.
If there is a new minor or patch release and we type npm update, the installed version is updated, and the package-lock.json file diligently filled with the new version.
Since npm version v.0.0, npm update will update the package.json with the updated version. Apply npm update --no-save to not update package.json.
To notice new releases of the packages, you run npm outdated.
Here'southward the listing of a few outdated packages in one repository that wasn't updated for quite a while:
Some of those updates are major releases. Running npm update won't update the version of those. Major releases are never updated in this way because they (past definition) introduce breaking changes, and npm wants to relieve you trouble.
To update all packages to a new major version, install the npm-check-updates package globally:
Bash
npm install -g npm-check-updates
then run it:
BASH
ncu -u
this volition upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version.
Y'all are now ready to run the update:
BASH
npm update
If you lot merely downloaded the projection without the node_modules dependencies and yous desire to install the shiny new versions first, just run
BASH
npm install
Source: https://nodejs.dev/learn/update-all-the-nodejs-dependencies-to-their-latest-version
Posted by: riveracamortautley.blogspot.com

0 Response to "How To Install Packages In Package Json"
Post a Comment