13 npm Tricks for Faster JavaScript Development
Speed up your JavaScript development workflow with npm and package.json
--
Every day, millions of developers reach for npm (or Yarn) for their JavaScript projects. Running commands like npm init
or npx create-react-app
has become the go-to way to begin almost any JavaScript project, whether you’re building code for the client-side or server-side — or even if you’re building a desktop app.
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:npm i
. - Testing— Regular:
npm test
. Shortcut:npm t
. - Getting Help— Regular:
npm --help
. Shortcut:npm -h
. - The Global Flag — Regular:
--global
. Shortcut-g
. - Saving as a Development Dependency — Regular:
--save-dev
. Shortcut:-D
. - Accepting npm init Defaults — Regular:
npm init --yes
ornpm init --force
. Shortcut:npm init -y
ornpm init -f
.
You no longer need to use --save
or -S
to save packages, as that is now the default. To install a package without saving it, use the --no-save
flag.
Less Common Shortcuts
There are also a handful of less common shortcuts, including:
- Saving as an Optional…