Apply npm best practices, including package.json, maintaining dependencies, security, release automation and monorepos.
You can publish multiple related npm packages under one scope: @scope/package-name
. Then you get the freedom to name packages, while clarifying which project they belong to.
Define the following fields in package.json
:
name
- package name (format docs)version
- package version following semantic versioningdescription
- a short description indexed by npm searchkeywords
- an array of case-insensitive strings indexed by npm search. Use letters, digits and dashes for better discoverability in search.homepage
- project website or repository URLrepository
- repository URLbugs
- issue tracker URLauthor
or contributors
- package developer(s) field formatlicense
- use "MIT" (most popular option) or choose a license from the listmain
- path to the main package entry pointpackage.json
being a JSON file doesn't support comments (such as // ...
). However, you can use custom fields to save notes without interfering with npm. For example, "comment": "...comment goes here..."
.
The best way to run several npm scripts in parallel is to use npm-run-all or concurrently.
Don't use cmd1 & cmd2
for that purpose. In Linux it will run cmd1
as a background process, which may not be automatically killed once finished.
require()
'd by other packages) dependencies use version ranges, preferably ^
. It prevents package duplication in user installations. Feel free to pin exact versions in devDependencies
.~
and ^
depending on how well they follow semantic versioning.package.json
sub-dependencies can only be pinned using a lock file.package.json
and lock files don't always stay in sync. This can lead to surprises in how npm install
works. For dependencies consistent between two files the version in lock file is used, while inconsistencies are resolved using package.json
.npm ci
or yarn install --frozen-lockfile
to ignore package.json
while installing packages.package-lock.json
, that are not bundled into npm packages, npm-shrinkwrap.json
is preserved and respected by npm install
. While it allows to pin the exact versions of sub-dependencies, it also leads to duplicate package installations and stale dependencies. Using npm-shrinkwrap.json
is strongly discouraged for libraries, but acceptable for command line tools, daemons and development dependencies.There are several ways to update dependencies manually:
These services can automatically identify packages to update and create pull requests for your repository:
node_modules
with cost-of-modules or npm download size. The size of individual packages can be estimated with Package Phobia.Note that if .npmignore
is provided then files listed in .gitignore
are no longer excluded from npm package. Make sure to blacklist all unnecessary files in
.npmignore
or whitelist them using files
field in package.json
.
.nyc_output
) from the package using .gitignore
or files
property of package.json
.npm publish --dry-run
.Bower has not been actively developed since 2016 and it's creator, Adam Stankiewicz, recommends to move aways from it. You can consider dropping Bower support by following the official guide.