Node Process Manager

Node Package Manager (NPM)

Nodejs

Free Online Tutorials on JavaScript, Node.js, React.js, PHP, JAVA, Python, HTML, GraphQl, TypeScript, MEAN, MERN Stack, etc.

Node Package Manager - NPM

NPM is the Package Manager for Node.js packages/modules
Install NPM:

NPM is installed by default when you install Node.js

Benefits of NPM:
  1. It Provides and hosts Online repositories for node.js packages/modules which can be easily downloaded and used in our projects. You can find them here: npmjs.com
  2. It Provides the Command-line utility in order to install various Node.js packages, manage Node.js versions and dependencies of the packages.
NPM useful commands:
Check NPM Version
 npm -v
Install Packages via NPM
  1. Installed packages goes inside node_modules folder.
  2. In Short you can use - npm i <package_name>
  3. You can check out npm packages - npmjs.com
  4. In Latest version, --save is optional. it automatically save the package as a dependency in package.json
Syntax:
npm install <package_name>

Install the package globally

npm install <package_name> -g

Save the package as dependency

npm install <package_name> --save

Save the package as dev-dependency

npm install <package_name> --save-dev

Install the latest version of a package

npm install <package_name>@latest

Install any particluar version of a package

npm install <package_name>@<version_number>

//npm install express@4.11.1
Uninstalling Packages/Modules via NPM
 npm uninstall <package_name>
Update Packages/Modules via NPM
 npm update <package_name>

 //aliases: up, upgrade
List all Installed Packages
 npm ls
package.json
{
  "name": "MyNodeProject",
  "version": "1.0.0",
  "description": "My Nodejs Project",
  "main": "app.js",
  "author": {
    "name": "Dev",
    "email": "dev@xyz.com"
  },
  "dependencies": {
    "body-parser": "~1.10.2",
    "express": "~4.11.1",
    "nodemon": "^1.14.12"
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-jshint": "^0.10.0",
    "jshint-stylish": "^0.2.0",
    "time-grunt": "^0.3.2"
  }
}