npm init or
But there’s a lot more to npm than initialising projects or installing packages. In this article, we’ll discuss 13 tricks to get the most out of npm: from simple shortcuts to custom
npm init scripts.
Since many of us use npm every day, even saving a small amount of time could make a significant difference in the long run. These tricks are aimed at beginner and intermediate developers, but even if you’re an experienced developer, I hope you still find one or two features that you hadn’t encountered before.
Finally, if you’re completely new to npm, it comes bundled with Node.js, which you can install at https://nodejs.org/en/. If you’re on Windows, I recommend installing Git Bash to follow along. Let’s dive in.
1. Learn the Essential Shortcuts
We’ll start with the basics. A short time spent learning the most common npm shortcuts will mean time-saved in the long run.
- Installing — Regular:
npm install. Shortcut:
- Testing— Regular:
npm test. Shortcut:
- Getting Help— Regular:
npm --help. Shortcut:
- The Global Flag — Regular:
- Saving as a Development Dependency — Regular:
- Accepting npm init Defaults — Regular:
npm init --yesor
npm init --force. Shortcut:
npm init -yor
npm init -f.
You no longer need to use
-S to save packages, as that is now the default. To install a package without saving it, use the
Less Common Shortcuts
There are also a handful of less common shortcuts, including:
- Saving as an Optional…