Install Open Source Packages: You can install the packages to your projects based on your needs. Packages are a piece of code written by someone that will help other developers to easily establish the particular functionality easily by importing it.
Publishing your packages: You can also help other developers with your packages by publishing them at npm
It is one of the most important advantage of npm. It is completely free for everyone that's why it is more popular and powerful.
Every library has its own dependencies and without these dependencies the library or package dont work. It's a very hectic work for the Developer to install all the dependencies but npm automatically installs it for us when we install the package or library.
The packages installed via npm are updated frequently. It takes care thar we always use the latest version of the package. Npm automatically updates the package to the current stable version of that package.
It is easy to use for any users we have a group of commands that are readable and easily understood for beginners.
The documentation of npm is in a well structured format easy to refer to all commands and their description. Do refer the npm docs.
The prerequisite for installing npm is Node.js as npm comes along with Node.js. To install Node.js visit its website.
Your project must contain a package.json file which keeps tract of all the packages you are using in your project.You can create one by
cd myproject npm init
The install command is used to install a particular package in your system i.e the install command followed by the package name.
C:\>npm install <package>
>npm install <package>
The --save flag ensures that your library is added to package.json file.
npm install <package> --save
The Uninstall command removes the package from the project.
$ npm uninstall <package>
The update command helps to update the version of the package and also the dependencies of that particular package.
$ npm update <package>
The search command is used to search for a particular package by thier name in npm.
$ npm search <package>
To publish your package or directory into npm you have to have a package.json file so to get it navigate to the directory and
$cd mypackage $npm init
To check whether you have logged in or not.
if not login then Type your Username and password
$npm login Username: <your username> Password: <your password>
Publish your package using the publish command after logging in
$ npm publish