Skip to content

Instantly share code, notes, and snippets.

@ipekt
Last active July 5, 2021 05:27
Show Gist options
  • Select an option

  • Save ipekt/90e187ad2029f7612a8120273ab2580a to your computer and use it in GitHub Desktop.

Select an option

Save ipekt/90e187ad2029f7612a8120273ab2580a to your computer and use it in GitHub Desktop.
npm cheetsheet

NPM Cheetsheet

INSTALL

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

CONFIG

Shows config

npm config list

Show all config

npm config ls -l

Get bin location

npm config get prefix

PACKAGES

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

Easter Eggs

These are listed at: https://gist.github.com/MohammadYounes/3ab53cbedd55d95cfa25

npm xmas

npm visnup

npm substack

NPM as Build tool

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

For more detailed information

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/

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