There are various things to note on the topic of install NPM package. Here, we will discuss them.
Benefits of using external NPM Package
- Reusable modules thus saving development time
- Reduce complexity of codes
Methods to Uninstall NPM Package
This can be perform in the global scope and project scope. Lets looks into them.
Install Packages Locally
To install a locally installed package, you must first navigate to the project root folder where node_modules folder and package.json file are located inside.
1. Install package to node_modules only.
Although the official documentation only mention that it will only install from node_modules folder, this command will also install package into `package.json` from my experiments.
npm install <package_name>
2. Install towards dependencies in package.json.
npm install --save <package_name> # or npm install -S <package_name>
3. Install towards devDependencies in package.json.
npm install --save-dev <package_name> # or npm install -D <package_name>
Globally Installed Packages
When installing package globally, you can be at any folder since the command will always access a standard directory.
Since it is global, there is no concept of dependencies and devDependencies. Just add a `-g` flag to the command to indicate global.
npm install -g <package_name> # Validating what is in the global npm list –g
Here, we learn the commands to correctly install NPM package via CLI based on conditions by indicating with a flag in the command.
If you have installed and want to uninstall, we have a tutorial on how to uninstall here.