Cover image for Lesser known npm CLI commands

Lesser known npm CLI commands

christopherkade profile image Christopher Kade Originally published at christopherkade.com ・2 min read

We all know and use npm start, npm audit, npm init and many more npm commands on a daily basis, but there are quite a few of them that are underutilized ! This article is here to show you some awesome things you can do with the npm CLI.

npm pack

Create a tarball from a package

If you're developing an npm package and want to test if it installs without publishing, running npm pack will package your module into a tgz file that can be installed using npm install.

npm pack

πŸ“„ Docs

npm outdated

Checks for outdates packages

Pretty self-explanatory, it checks the registry if any of the currently installed packages are outdated.

npm outdated

πŸ“„ Docs

npm prune

Remove extraneous packages

Removes packages that are not listed on the parent package's dependencies list.

npm prune

πŸ“„ Docs

npm star <pkg>

Mark your favorite packages

Allows you to show some love for a given package.

npm stars lists your currently starred packages.

πŸ“„ Docs

npm view <name> <field>

View registry info

npm view

You may also add any field that can be found in a package.json such as dependencies to view the related information.

πŸ“„ Docs

npm docs <pkg>

Docs for a package in a web browser

How many times did you end up looking for a package's documentation manually? Running npm docs <pkg> will automatically open the relevant page for you (only if it is listed in the package's package.json file).

πŸ“„ Docs

npm dedupe

Reduce duplication

Dedupe searches the local package tree and tries to simplify its structure by moving dependencies further up the tree. This way, they can be shared more effectively by multiple dependent packages.

πŸ“„ Docs

npm completion

Tab Completion for npm

Running npm completion will display a bash script that will take care of auto-completion of any future npm command. All you have to do is follow the instructions given by the command.

In my case, npm completion >> ~/.bashrc was enough for me to take advantage of that feature !

npm completion

πŸ“„ Docs

And that's enough for one day !

Some of these commands are really, really useful in my opinion so I hope you've enjoyed this article.

If you did, following me on Twitter @christo_kade is probably the best way of showing your support. I post a lot about some cool open-source things I find, JS & CSS tricks and much more.

Thank you for reading !

Posted on by:

christopherkade profile

Christopher Kade


Web consultant @ZenikaIT // I sometimes record podcasts, build things and write about the web πŸ‘‹


Editor guide

One trivia for npm is that npm isntall is a legit working command, as an alias to npm install πŸ˜‚For details: github.com/npm/npm/issues/2933#iss...


Hahaha, today I learned πŸ˜†


This made my day, thanks for sharing πŸ˜„


Great list Christopher. I haven't used some of these commands yet so this is really good to know.

I wanted to add:

npm version <major|minor|patch>

as well for bumping up the version of your app in your package.json for semantic versioning. I honestly didn't know that you could automatically do this until recently 😲


Thank you Ana Liza !

Agreed, npm version is a good one to know, thanks for sharing it.


Wow new to this site. Impressed as articles like this usually are the same shared commands.