NPMでコマンドは多いですが、普段使うコマンドはそんなに多くありません。
npmで利用できるコマンドを確認するコマンドは npm -lです。
npm -l
結果:
Usage: npm
where is one of:
access npm access public [<package>]
npm access restricted [<package>]
npm access grant <read-only|read-write> <scope:team> [<package>]
npm access revoke <scope:team> [<package>]
npm access ls-packages [<user>|<scope>|<scope:team>]
npm access ls-collaborators [<package> [<user>]]
npm access edit [<package>]
adduser npm adduser [--registry=url] [--scope=@orgname] [--auth-type=legacy] [--always-auth]
aliases: login, add-user
audit
npm audit [--json]
npm audit fix [--force|--package-lock-only|--dry-run|--production|--only=(dev|prod)]
bin npm bin [--global]
bugs npm bugs [<pkgname>]
alias: issues
cache npm cache add <tarball file>
npm cache add <folder>
npm cache add <tarball url>
npm cache add <git url>
npm cache add <name>@<version>
npm cache clean
npm cache verify
ci npm ci
completion source <(npm completion)
config npm config set <key> <value>
npm config get [<key>]
npm config delete <key>
npm config list [--json]
npm config edit
npm set <key> <value>
npm get [<key>]
alias: c
dedupe npm dedupe
aliases: ddp, find-dupes
deprecate npm deprecate <pkg>[@<version>] <message>
dist-tag npm dist-tag add <pkg>@<version> [<tag>]
npm dist-tag rm <pkg> <tag>
npm dist-tag ls [<pkg>]
alias: dist-tags
docs npm docs <pkgname>
npm docs .
alias: home
doctor npm doctor
edit npm edit <pkg>[@<version>]
explore npm explore <pkg> [ -- <command>]
get npm get <key> <value> (See `npm config`)
help
help-search npm help-search <text>
hook
init
npm init [--force|-f|--yes|-y|--scope]
npm init <@scope> (same as `npx <@scope>/create`)
npm init [<@scope>/]<name> (same as `npx [<@scope>/]create-<name>`)
aliases: create, innit
install
npm install (with no args, in package dir)
npm install [<@scope>/]<pkg>
npm install [<@scope>/]<pkg>@<tag>
npm install [<@scope>/]<pkg>@<version>
npm install [<@scope>/]<pkg>@<version range>
npm install <folder>
npm install <tarball file>
npm install <tarball url>
npm install <git:// url>
npm install <github username>/<github project>
aliases: i, isntall, add
common options: [--save-prod|--save-dev|--save-optional] [--save-exact] [--no-save]
install-test
npm install-test [args]
Same args as `npm install`
alias: it
link npm link (in package dir)
npm link [<@scope>/]<pkg>[@<version>]
alias: ln
logout npm logout [--registry=<url>] [--scope=<@scope>]
ls npm ls [[<@scope>/]<pkg> ...]
aliases: list, la, ll
outdated npm outdated [[<@scope>/]<pkg> ...]
owner npm owner add <user> [<@scope>/]<pkg>
npm owner rm <user> [<@scope>/]<pkg>
npm owner ls [<@scope>/]<pkg>
alias: author
pack npm pack [[<@scope>/]<pkg>...] [--dry-run]
ping npm ping
ping registry
prefix npm prefix [-g]
profile npm profile enable-2fa [auth-only|auth-and-writes]
npm profile disable-2fa
npm profile get [<key>]
npm profile set <key> <value>
prune npm prune [[<@scope>/]<pkg>...] [--production]
publish npm publish [<tarball>|<folder>] [--tag <tag>] [--access <public|restricted>] [--dry-run]
Publishes '.' if no argument supplied
Sets tag `latest` if no --tag specified
rebuild npm rebuild [[<@scope>/<name>]...]
alias: rb
repo npm repo [<pkg>]
restart npm restart [-- <args>]
root npm root [-g]
run-script npm run-script <command> [-- <args>...]
aliases: run, rum, urn
search npm search [--long] [search terms ...]
aliases: s, se, find
set npm set <key> <value> (See `npm config`)
shrinkwrap npm shrinkwrap
star npm star [<pkg>...]
npm unstar [<pkg>...]
alias: unstar
stars npm stars [<user>]
start npm start [-- <args>]
stop npm stop [-- <args>]
team npm team create <scope:team>
npm team destroy <scope:team>
npm team add <scope:team> <user>
npm team rm <scope:team> <user>
npm team ls <scope>|<scope:team>
npm team edit <scope:team>
test npm test [-- <args>]
aliases: tst, t
token npm token list
npm token revoke <tokenKey>
npm token create [--read-only] [--cidr=list]
uninstall npm uninstall [<@scope>/]<pkg>[@<version>]... [--save-prod|--save-dev|--save-optional] [--no-save]
aliases: un, unlink, remove, rm, r
unpublish npm unpublish [<@scope>/]<pkg>[@<version>]
update npm update [-g] [<pkg>...]
aliases: up, upgrade, udpate
version npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
(run in package dir)
'npm -v' or 'npm --version' to print npm version (6.4.1)
'npm view <pkg> version' to view a package's published version
'npm ls' to inspect current package/dependency versions
view npm view [<@scope>/]<pkg>[@<version>] [<field>[.subfield]...]
aliases: v, info, show
whoami npm whoami [--registry <registry>]
(just prints username according to given registry)
helpのコマンド
npm -h quick help on
npm -l display full usage info
npm help search for help on
npm help npm involved overview
よく使うコマンドは、init,install,run,auditなどですね。
特にセキュリティパッチがあるかのチェックするauditコマンドは便利です。
=== npm audit security report ===
found 0 vulnerabilities
in xxx scanned packages
[0 vulnerabilities]であればおそらくよいでしょう。
メンテンナスに便利なnpm-check-updates
インストール:npm install -g npm-check-updates
チェック
ncu
update
ncu -u
その他オプション
Usage: ncu [options] [filter]
[filter] is a list or regex of package names to check (all others will be ignored).
Options:
-d, --dev check only devDependencies
-e, --error-level set the error-level. 1: exits with error code 0 if no errors occur. 2: exits with error code 0 if no packages need updating (useful for continuous integration). Default is 1. (default: 1)
-f, --filter include only package names matching the given string, comma-delimited list, or regex
-g, --global check global packages instead of in the current project
-j, --jsonAll output new package file instead of human-readable message
--jsonUpgraded output upgraded dependencies in json
-l, --loglevel what level of logs to report: silent, error, minimal, warn, info, verbose, silly (default: warn) (default: "warn")
-m, --packageManager npm (default) or bower (default: "npm")
-n, --newest find the newest versions available instead of the latest stable versions
-o, --optional check only optionalDependencies
--packageData include stringified package file (use stdin instead)
--packageFile package file location (default: ./package.json)
--packageFileDir use same directory as packageFile to compare against installed modules. See #201.
-p, --prod check only dependencies (not devDependencies)
--peer check only peerDependencies
-r, --registry specify third-party npm registry
--configFilePath rc config file path (default: ./)
--configFileName rc config file name (default: .ncurc.{json,yml,js})
-s, --silent don't output anything (--loglevel silent)
-t, --greatest find the highest versions available instead of the latest stable versions
--timeout a global timeout in ms
-u, --upgrade overwrite package file
-x, --reject exclude packages matching the given string, comma-delimited list, or regex
-a, --upgradeAll include even those dependencies whose latest version satisfies the declared semver dependency
--semverLevel find the highest version within "major" or "minor"
--removeRange remove version ranges from the final package version
-v, --version 2.15.0
-V
-h, --help output usage information
以上