What is NPM
NPM is the largest software repository in the world. Many companies use npm to manage private development in addition to its widespread use by open-source developers all around the world to share and borrow packages.
NPM consists of three distinct components:
- Website
- Command Line Interface (CLI)
- Registry
Use the website to discover packages, set up profiles, and manage other aspects of your NPM experience. For example, you can set up organizations to manage access to public or private packages.
The CLI runs from a terminal and is how most developers interact with npm.
The registry is a large public database of JavaScript software and the meta-information surrounding it.
NPM is a command-line program that helps with package installation, version control, and dependency management. It is also an online repository for the publication of open-source Node.js projects. The number of Node.js modules and apps available on npm continues to grow exponentially. You can find these programs by visiting https://www.npmjs.com/. There is only one command required to install a package once you have it.
Let’s say you’re hard at work one day, developing the Next Great Application. You come across a problem, and you decide that it’s time to use that cool library you keep hearing about — let’s use Caolan McMahon’s async as an example. Thankfully, npm
is very simple to use: you only have to run npm install async
, and the specified module will be installed in the current directory under ./node_modules/
. Once installed to your node_modules
folder, you'll be able to use require()
on them just like they were built-ins.
Let’s look at an example of a global install — let’s say coffee-script
. The npm command is simple: npm install coffee-script -g
. This will typically install the program and put a symlink to it in /usr/local/bin/
. This will then allow you to run the program from the console just like any other CLI tool. In this case, running coffee
will now allow you to use the coffee-script REPL.
Dependency management is another significant application of npm. When you have a node project with a package.json file, you can run npm install
from the project root and npm will install all the dependencies listed in the package.json. This makes installing a Node.js project from a Git repo much easier! For example, vows
, a Node.js testing framework can be installed from git, and its single dependency, eyes
, can be automatically handled:
Example:
Why do we use NPM
- Adapt packages of code for your apps, or incorporate packages as they are.
- Download standalone tools you can use right away.
- Run packages without downloading using npx.
- Share code with any npm user, anywhere.
- Restrict code to specific developers.
- Create organizations to coordinate package maintenance, coding, and developers.
- Form virtual teams by using organizations.
- Manage multiple versions of code and code dependencies.
- Update applications easily when the underlying code is updated.
- Discover multiple ways to solve the same puzzle.
- Find other developers who are working on similar problems and projects
More information about NPM
digital clock npm for react
Follow me on GitHub: MadhushaPrasad