-
npm install -g packagename
,npm uninstall -g packagename
-
npm install -g gitbook-cli --save
-
gitbook versions
,gitbook versions:install 2.6.7
,gitbook versions:uninstall 2.6.7
,gitbook init
,gitbook install plugin
,gitbook serve
,gitbook serve --port 8001
,gitbook build
,gitbook pdf book pdf
-
npm list -g --depth=0
,npm root -g
,npm view <module_name> versions
,npm view <module_name> version
,npm outdated -g --depth=0
,npm install -g <module_name> --save
,npm update -g <module_name>
,npm list
,npm list --depth=0
,npm list -g --depth=0
,npm uninstall -g <module_name>
-
npm prune
Sometimes after installing packages, you realize that you dont really need some of them and you delete those entries from your package.json. Although those packages will not be installed again on running an npm install, you still need to remove them from your node_modules folder at least once. To remove all such unused packages from your node_modules, you can run the command -
npm prune --production
If you just want to delete all of your installed devDependencies while retaining their entry in the package.json file, you can do that using the command -
npm install -g express --save
The above command not only installs the latest version of the package ‘express’ for you but it also updates your package.json file and adds the package name and the installed version number to your dependencies map.This way, the next time you clone your package, or delete your node_modules folder and then issue the npm install command, npm will install exact same versions of your packages that were specified in your package json therefore preventing your code from breaking due to updates to packages. -
The next interesting happens when you realize that you actually have two kinds of packages — ones that are required for your applications to run and others that you use as tools that help you during development — such as
jshint
,grunt
,grunt tasks
, minification,sass compilers
etc etc.Since these packages are only required by the developer, they dont need to be installed by someone else that might use your package in the future. The reason why it is important to make this distinction is because when someone else who mentions your package as dependency in their project issues annpm install
, npm will also go ahead and install all the packages specified in your ‘dependencies’. npm cannot distinguish between mandatory packages and development-only packages. Well at least not unless you tell it to.The correct way to specify development only packages is by listing them in yourpackage.json
under the key ‘devDependencies’. And just like before, you don’t need to remember the package version numbers of these packages. You can install them by simply running the npm install command with the–save-dev
option as shown,npm install grunt --save-dev
.Just like the–save
option, the–save-dev
option updates your package.json file but this time it adds an entry to yourdevDependencies
map thereby helping you make a clear distinction between required-to-run packages and development-only packages. -
If you just want to delete all of your installed devDependencies while retaining their entry in the package.json file, you can do that using the command.
npm prune --production
After this command, the only packages left in your node_modules directory will be the ones that are specified in your dependencies map. -
Sometimes after installing packages, you realize that you dont really need some of them and you delete those entries from your package.json. Although those packages will not be installed again on running an npm install, you still need to remove them from your node_modules folder at least once. To remove all such unused packages from your node_modules, you can run the command
npm prune
. -
If at any time, you want uninstall a module, you can do that by the command
npm uninstall packagename
And just like thenpm install
command, theuninstall
command also takes accepts–g
,–save
and–save-dev
to removeglobal modules
and update thepackage dependencies
ordevDependencies
respectively.