DEV Community

Cover image for Lesser known npm CLI commands
Christopher Kade
Christopher Kade

Posted on • Originally published at christopherkade.com

Lesser known npm CLI commands

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 !

Top comments (6)

Collapse
 
briwa profile image
briwa

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...

Collapse
 
analizapandac profile image
Ana Liza Pandac

Hahaha, today I learned πŸ˜†

Collapse
 
christopherkade profile image
Christopher Kade

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

Collapse
 
analizapandac profile image
Ana Liza Pandac • Edited

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 😲

Collapse
 
christopherkade profile image
Christopher Kade

Thank you Ana Liza !

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

Collapse
 
dylajwright profile image
Dylan

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