Start your project (or module) off right
I'm surprised to hear how few people use this command. It is the de facto way to kick off a new project that uses npm: whether it's an npm module you plan to publish or just a project that will use npm modules. Use it.
Automate Common Tasks with npm scripts
npm test, and
npm run <your custom job>
Quite frankly, npm scripts should be the public API of your project automation.
npm startshould include the command to start the server and/or watch for changes and rebuild (preferably both). This is where your
[grunt|gulp] serveshould go.
npm testshould be run consistently to automate test coverage
npm run <anything-you-want>should be used to run any custom tasks that make your project easier to work on, like version-bumping, building (without running server), remote server tasks, etc.
When creating software, common sense tells us to depend on things that change less frequently (think public APIs) over things in flux (implementation details). So why do we admonish running build-library-specific commands in our documentation instead of using the established standard, which is NPM?
Save valuable keystrokes
npm install --save <some-module>just becomes too much typing.
npm i -S <some-module>will get you the same thing.
npm i -D <some-module>will get you the same thing except with the
--save-devoption instead of
Even better, you can just configure NPM to always save modules as you install them:
npm config set save true
npm i <some-module>is all you need after that.
npm prunewill clean out unneeded modules from your node_modules directory. If left to my own devices, this will get run twice a year.
There's no need to let your faulty memory disservice you again here: prefix your
prepublishnpm scripts with
npm prune && <rest-of-command>to ensure this happens regulary, and especially before you publish to the registry.
When all else fails: Getting Help
npm help, or even better:
This is a good place to start: it lists all the top-level commands, and some very basic info. Running the alternative
npm -lwill give you much more info on subcommands, and what each command expects for arguments.
npm help 7 config
I thank the NodeUp podcast specifically for this hidden gem. Using the easier to find
npm help configwill show you the help for
NPM-CONFIG(1), or in manpage speak, the help page for the user-level command
config. It turns out that is not so helpful for npm, since the only things you can do with it are get, set, list, delete, and edit entries (much like shell variables). However, what you probably want is all the helpful configuration options available to you via the commandline args and config file
~/.npmrc, and that is what you'll find at
npm help 7 config