npm - Node Package Manager
npm handles the packages required for a project as well as the records of all dependencies, versions, and other crucial information.
How to install npm
Just go to Node Js
Install it with installer of your current os.
And npm will install with nodejs.
to check whether npm installed you can check npm version with command
npm -v
in your favourite terminal.
npm benefits
Pre-installed with node.js
Easily install package/module in your system.
initialize npm
Open Terminal in repository you want to make your project.
give command
npm init
to create new package.it takes some details like author , license ,git-repo etc.
if you want to continue with default details which is easy and time saving to create package there is command
npm init --yes
.after package is created it creates the file with name package.json
install package
To install package there is command
npm install package_name --save
. It install package locally in that repo.To install package globally (into your whole system) use
npm install package_name -g
.--save
saves the dependency version in package.json file.And if you use
npm install package_name --save-dev
it will save package as devDependencyTo uninstall package there is command
npm uninstall package_name --save
.And it is similarly applicable for devDependency.
Version System
Generally in npm version is #.#.# this type of arrangement in which # contains numbers from 0 to unlimited.
Major Version → It is version which conatin new features than previous version and also it can break the project if use in uncompatible type.
Minor Version → This version contains minor updates and features and it can't break the project.
Patch → Patch is just some bug fixes and it doesn't break anything.
npm update
To update the package npm update package_name
command is use. There are 4 parameters or flags that denote whole version system and updates which contains in dependencies section in package.json file.
==Symbols mention below can see in "dependencies" section after "express" package.==
^ → If you use update command in project it updates only minor version that means major version so much important for the project.
~ → It only updates the patch.
[No Sign] → You have to install exact version . e.g. if it shows 4.7.9 you have to install exactly this version. To install exact version you can use
npm install package_name@versionNumber
.→ If there is only '*' in dependencies it means it updates most latest version of that package (But it is not recommended.)
Concepts use in this blog
Dependency
It is package which is essential for running the project. or the package which is use only while production.
devDependency
devDependency is dependency which is useful for testing and development.
package.json file
Contain details like author,license,script etc.
Contain all the list of dependencies.
Also contain all the version numbers.