Skip to content

Instantly share code, notes, and snippets.

@migliori
Last active February 13, 2024 06:33
Show Gist options
  • Save migliori/a14153a0d6b0e927db157801ba48b73e to your computer and use it in GitHub Desktop.
Save migliori/a14153a0d6b0e927db157801ba48b73e to your computer and use it in GitHub Desktop.
NPM Cheatsheet #npm #cheatsheet

NPM Cheatsheet

remove unused packages from package.json

https://www.npmjs.com/package/npm-check

list the unused packages in package.json

#install
npm install -g npm-check

#use
npm-check

clean node_modules

https://docs.npmjs.com/cli/prune

removes the node_modules unlisted in package.json

npm prune

publish package

https://docs.npmjs.com/cli/publish

npm publish [< tarball >|< folder >] [--tag < tag >] [--access < public|restricted >] [--otp otpcode]

Publishes '.' if no argument supplied
Sets tag 'latest' if no --tag specified

version

https://docs.npmjs.com/cli/version

npm version [< newversion > | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]

'npm [-v | --version]' to print npm version
'npm view <pkg> version' to view a package's published version
'npm ls' to inspect current package/dependency versions

The newversion argument should be a valid semver string, a valid second argument to semver.inc (one of patch, minor, major, prepatch, preminor, premajor, prerelease), or from-git.

In the second case, the existing version will be incremented by 1 in the specified field. from-git will try to read the latest git tag, and use that as the new npm version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment