To upgrade to the highest acceptable version locally just run (to update globally just add -g flag and run as root): npm update To check out which packages can be updated locally and globally, run respectively: npm outdated To see all locally installed packages use ls command and add -l flag for short description and -depth=0 for brevity and scope (add -g flag if you wish to see global packages): npm ls -l -depth=0
It will install the modules and change the asterisks to installed version number with ^ allowing for minor and patch updates. Note: If you are not sure which version to use, just put "*" and run npm update -save.
"package1 " : "1.0.0 ", // accepts only 1.0.0 version "package2 " : "1.0.x ", // any patch release in version 1.0 "package3 " : "* ", // latest version, not recommended "package4 " : ">=1.0.0 ", // any changes after 1.0.0 "package5 " : "= 1.8.0 =1.1.0 =2.3.1 =2.5.2 <3.0.0 "įor a more granular approach consult the NPM semantic version documentation.īe sure to follow best-practices and patch versions of the packages so your code won’t break. You can update them and still preserve compatibility by specifying the range of accepted updates. Let’s say you start developing with certain versions of the packages. Patch release with bug fixes and other minor changes, e.g.Minor release with new features that don’t break existing features, e.g.Major release which breaks backwards compatibility, e.g.NPM uses semantic versioning, a standard to communicate what kind of changes are implemented in the release as it affects code stability.Ī release number typically contains three elements: You can control which kind of updates your project accepts in the package.json file. Open source projects often move fast, and versions change frequently. NPM lets you manage your project dependencies and the versions you need. That method is reserved mostly for command line utilities. It’s not advised to install every package globally.
JShint should now be installed as a global package on the computer and can be ran from anywhere on a JavaScript file to lint it in a terminal. It is commonly used for packages that provide command line functionality, such as grunt, bower and yo.įor example, to install JSHint globally, run the install command with -g flag and root privilege: sudo npm install -g jshint Global instalationĪnother way to install a package is by doing a global installation.
This is good as it lets each project define its modules, their specific version and download them separately.
You can create a package.json file manually or bootstrap it interactively from the command line. To check if it is installed just run: npm -v If you have Node.js installed, npm command will be available. It is a manifest file which tracks your dependencies, provides some metadata for your project and can optionally define some project-specific tasks to perform from command line. When you start a new project utilizing Node.js, you need to create a package.json file. This tutorial is an introduction to what you can do with NPM and a reference to its most frequently used commands.
All those packages are listed on the official NPM website and in the NPM registry, the database of all available the open source packages. Since JavaScript is now being used both for client and server-side code, there are lots of different packages: some for server side, some that are in fact command line programs and some that are made for front-end development. NPM makes is easy to reuse thousands of existing open source packages that solve a multitude of common problems, as well as share your own code with the community through the NPM registry.
It keeps track of all dependencies for your Node.js projects and gives you full control over managing them. NPM is a Node.js package manager that comes bundled with the installation of Node.js.