Installing modules using npm
The module system in Node is very powerful that consuming a third-party module written by other developers is a piece of cake. Node includes its own package manager called npm, which is a registry that currently contains over 475,000 modules written in Node. These modules are completely open source and available to you via a few short commands. In addition, you can release your own personal modules via npm and allow anyone in the world to use your feature!
Let's say you want to include a popular web framework, express
, in your project (the one we will be using later in this book). There are two simple steps required to download a module and use it in your code:
$ npm install express// ** file: usingnpm.jsvar express = require('express');
And that's it! Literally, it's that simple! From the command line of the folder where your project is located, simply execute npm install package-name
, and the package will be downloaded from npm and stored in a folder called node_modules...