npm is Node’s package manager, a registry of modules written in Node.js. Two simple steps are required to use a module in your code.
npm install express // via terminal, installs express framework var express = require(‘express’); // in your .js home file
The module will be installed in the
node_module folder. There you will find a new folder for the package you installed that contains the raw source code for the package itself.
You can install a module globally, not within the project folder you are currently using. To do that just add
Node projects include a
package.json file which lists all of the npm packages installed, among other information related to the project. The packages you are installing can be saved into the
package.json file using
--save-dev flags when installing the package via npm.
package.json file can be created automatically via terminal by executing the command
npm init and answer a few questions about the project.
package.json file have two sections called “dependencies” and “devDependencies”. The
dependencies section is very important for the application to function properly while the
devDependencies contains just packages that are used by the developer during the development time (usually for testing purposes).