When you install a package using
npm install <packagename> , the latest available version of the package 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 present in your current folder.
In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X =0.1.0, and no updates for versions 0.0.X. Many authors treat a 0.x version as if the x were the major “breaking-change” indicator. This fast, production ready, zero dependency loader is all you need to support ECMAScript modules in Node 6+. See the release post and video for details! New projects. Run npm init esm or yarn create esm. ? Use the -y flag to answer “yes” to all prompts. Existing projects. Run npm i esm or yarn add esm. Getting started.
npm calculates the dependencies and installs the latest available version of those as well.
Let's say you install
cowsay , a cool command line tool that lets you make a cow say things.
When you
npm install cowsay , this entry is added to the package.json file:
and this is an extract of
package-lock.json , where we removed the nested dependencies for clarity:
Now those 2 files tell us that we installed version
1.3.1 of cowsay, and our rule for updates is ^1.3.1 , which for the npm versioning rules means that npm can update to patch and minor releases: 1.3.2 , 1.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.
package.json remains unchanged.
To discover new releases of the packages, you run
npm outdated .
Here's the list 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 (by definition) introduce breaking changes, and npm wants to save you trouble.
To update to a new major version all the packages, install the
npm-check-updates package globally:
then run it:
this will upgrade all the version hints in the
package.json file, to dependencies and devDependencies , so npm can install the new major version.
You are now ready to run the update:
If you just downloaded the project without the
node_modules dependencies and you want to install the shiny new versions first, just run
Contributors
Today I was listening to the NodeUp episode 70, which is all about the npm command line client. And there is tons of useful information in this episode. It is all about where npm is at the moment and what the plans are for the future. Especially the recent changes inside of the command line client are a heavy discussed topic and I highly recommend to listen to this episode, when you are dealing with npm on a daily basis.
One thing that is mentioned and really gets me excited is the change regarding the functionality to run scripts via npm which was introduced in the latest major version of npm – [email protected].
So let us reassess how to run scripts via npm, have a look at what has changed in version 2.0.0 and check why this is such a big deal.
Running scripts via npm
The configuration file for any project based on node and npm is the
package.json . This file includes meta information like name, version and author of the depending project, but also defines all dependencies, which need to be installed via calling npm install . If you are not familiar with this file, there is an excellent interactive cheat sheet out there and you may want to check it out.
One thing to notice is that you can also run scripts and execute commands via npm. To do so you can define an optional object as the
scripts property inside of the package.json and define your wished commands. @substack wrote a great article about how to use this functionality extensively.
There is not much magic about this.
And then you can use
npm run to kick it off – pretty straight forward.
This functionality had one downside so far. It was not able to pass arguments to the
npm run command. And that is why you had to hardcode the arguments, which made the whole thing less flexible and harder to use. The only solution for having similar commands with different arguments was to define specific named scripts inside of the package.json including different arguments.
Passing arguments to
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |