NPM stands for the Node Package Manager. It is responsible for handling the dependencies required for the node. It helps to install modules/packages on your system.
Installation
You should have node.js installed in your system. Npm is pre-installed in it.
Initializing the Node Directory
npm init
In my system, I am using gitbash
as a terminal. When you initialize the npm, You will have a series of questions including author name, license, name, etc. All this file will be saved in the file named package.json
.
If you want to skip all the question, you can do that by using the command
npm init --y
OR
npm init --yes
Package.json
- It is a manifest file with app info. 2.It contains dependencies such as name, version, etc. 3.It help to update the version of dependencies using
This is how package.json may look like
{
"name": "npmapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
}
Now if you want to change just the author name and want to skip the other question simultaneously, You can do it by following the steps
npm config set init-author-name "Hans Zimmer"
npm init
You can set the other defaults as well such as version, using npm config set
A package.json will be made with the author's name as Hans
Zimmer. Note that you have to delete the existing package.json file to get another package.json file
How to get Default
npm config get init-author-name
It will Return you Hans Zimmer.
Local Packages
Installation
npm install lodash --save
OR
npm install --save lodash
Uninstallation
npm uninstall lodash --save
OR
npm uninstall --save lodash
Dev dependencies
Installation
npm install gulp gulp-sass --save-dev
Uninstallation
npm uninstall gulp gulp-sass --save-dev
Global Packages
Nodemon is one of the global package.
Installation
npm install -g nodemon
Uninstallation
npm uninstall -g nodemon
Find the root folder of global package
npm root -g
Listing packages
npm list
npm list --depth 0
npm list --depth 1
Thank you