npm init
npm install || i <package-name>
npm remove || uninstall || rm || un <package-name>
npm update <package-name>
When you initialize node package with npm init
you have to answer some questions. If you use -y or --yes flag like this npm init -y || --yes
you don't have to answer those questions. It will setup the package.json file with default configurations.
npm init -y || --yes
If you want to install a package globally you can use -g or --global like this
npm install -g || --global
When you want to access your packages via terminal or you want to use packages offline you have to install it globally to your computer. It means package you're installing not only accessible in that folder instead it will access everywhere on your computer you don't have to create scripts to run those commands.
When you installing a new package you have to add that package as a dependency into package.json file this flag do it for us.
npm install <package-name> -s || --save
Note: if you are using current version npm you are no need to add this flag npm install command automatically added that package as a dependency.
If you don't want to add you're package as a dependency.
npm install <package-name> --no_save
If you want to install your package as a dev dependency you want to use this flag.
npm install <package-name> --save-dev
Install only Production dependencies
npm install --production
Install package as a optional dependency
npm install <package_name> --save-optional || -O
Install specific version of package
npm install <package-name>@<version number>
Ex npm install lodash@1.0.0
Every node package has a version with three numbers separated by "." sign.
-
The first number represents a major version it can have breaking changes.
-
The second number represents Minor versions it will add new features to packages and it doesn't break your code most of the time.
-
The third number represents the patch version. It doesn't include any breaking changes.
-
* - if you completely remove version number and put '*' it will install the latest version of that package. It is not a good idea because major versions break your code.
-
^ - if this symbol is added in front of your version number when you run
npm install
it will install a latest minor version of that package
-
~ - if this symbol is added in front of your version number when you run
npm install
it will stick to that minor version and it will only update the patch version. -
if you put version number without any of those symbols i will install that specific version of that package
npm root -g
npm un || rm || remove || uninstall -g <package-name>
npm list
npm list --depth 0