fbpx

Series: Introduction to the MEAN Stack

npm  is a package manager for managing modules. That is, it makes installation and uninstallation of modules easier and also takes into account whether a particular module depends on another or not. It is installed by default with Node. In this article, I explain the use of npm.

Contrary to widespread opinion npm would be an abbreviation for Node Package Manager is npm not an abbreviation and also has no 100% meaningful meaning . When selecting the name as a command for the command line, care was taken that all letters can be entered easily with the right hand and without uppercase letters.

The current version of npm can be checked in the terminal:

1
2
$ npm  v
> 1.3.8

Although nod modules are distributed almost exclusively via npm, any other files can also be managed using npm.

As already shown, the creation and requisition of Node modules is very simple. npm improves this property of Node once again: Modules can be easily (de) installed and interdependencies between modules can be held. The (de) installation of modules can be done globally or locally. As a rule, modules are installed locally per project because projects can work with different versions of a module. The rule of thumb is merely to install Node modules, which are used as a command line tool, to be installed globally. All locally installed modules are stored in a subfolder of the current folder named node_modules .

The installation of a module is done by a simple command ( modulnamemust be replaced by a real name of a module):

1
$ npm install module name

With the addition -g after install , the module would be installed globally.

By uninstall the corresponding module can be uninstalled:

1
$ npm uninstall module name

The same command can be -g applied again with the addition for global modules.

npm provides a way to package.json hold the dependencies of a project declaratively in a JSON file named other modules . We do not need this function for the following simple examples. If you would like to know more about this common practice at this point, you can read it in the npm document at https://npmjs.org/doc/files/package.json.html . It is especially relevant for the release of its own Node modules at npm, or when working with other developers, so that each developer receives all the dependencies of a module. It can also contain metadata such as a link to the repository or information about the license.

Since we now know how to install external modules with npm, we can look at our first node framework in the next article.


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.