Interactive package.json generation
npm init
Install packages listed in package.json
npm install
npm i
Install packages as dependencies
npm install --save $package
npm i --s $package
Install packages as dev dependencies
npm install --save-dev $package
npm i -D $package
Uninstall a package
npm uninstall $package
List installed npm packages
npm list --depth=0
Uninstall packages that are not declared in package.json
npm prune
Shows config
npm config list
Show all config
npm config ls -l
Get bin location
npm config get prefix
Check for outdated packages
npm outdated
Update packages to latest as declared in package.json
npm update
Update given package
npm update $package
Open a package’s homepage
npm home $package
Open a package’s docs
npm docs $package
Open a package’s repo
npm repo $package
Create lock file, to lock down versions regardless of what is in package.json
npm shrinkwrap
Clean cache
npm cache clean
Link a package locally to a project
In package dir:
npm link
In project dir:
npm link my-package
Unlink a package from a project
In project dir:
npm unlink my-package
These are listed at: https://gist.github.com/MohammadYounes/3ab53cbedd55d95cfa25
npm xmas
npm visnup
npm substack
Run custom scripts
npm run $script
Run multiple scripts in sequel
npm run $script && npm test
Change directory and run script
(cd ../js && npm test)
-- can pass custom arguments to npm scripts
scripts: {
“test”: “mocha js/**.spec.js”,
“test:reporter”: “npm run test -- —reporter"
}
| as stdin and > stdout can be used in scripts.
*its also possible to add git hooks. https://www.npmjs.com/package/git-hooks
https://npmjs.org/doc/index.html
https://css-tricks.com/why-npm-scripts/
https://www.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/