Common commands

List globally installed packages

npm ls -g
npm ls create-react-app -g

Install as a global package

npm install foo --global

See more details about the command options:

Switch betweeen China-LAN and Internet

show current registry

$ npm config get registry

switch to taobao registry

$ npm config set registry

show current registry

$ npm config get registry

switch to official registry

npm config set registry

Or choose the registry when installing packages:

npm install --registry=

Publish a new package


login to and create token for login account

$ npm login

Publish package for the first time

$ npm publish
+ krpano@0.0.1

Update the package

prepare update version

$ git tag -l
$npm version patch
$ git tag -l

publish package

chenyang@chenyang-pc:~/source/tims-ocr-api$ npm publish
+ tims-ocr-api@2.0.5

update npm self

sudo npm update -g npm

install from private repo

branch is develop

npm install git+ssh:// --save

Rename package (deprecate old create new)

For example, the old package is ssc-grid@0.11.0 (latest version), name should changed to ssc-comp.

Change name in package.json to new one, also version number.

npm publish ... # 
npm deprecate ssc-grid@"< 0.12.0" "WARNING: This project has been renamed to ssc-comp. Install using ssc-comp instead."


package.json script order


    "build": "npm run clean && npm run build:js && npm run build:css && npm run build:svg",
    "build:js": "babel src/ -d lib/ --ignore src/components",
    "build:css": "node-sass css/styles.scss lib/css/_datepicker.css",
    "build:svg": "webpack",
    "clean": "rimraf lib",
    "precover": "rimraf coverage",
    "cover": "cross-env NODE_ENV=test node --max-old-space-size=2048 $(which nyc) npm run mocha test",
    "lint": "eslint --ext .js,.jsx src test",
    "mocha": "mocha ./test/_helpers",
    "react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils",
    "react:14": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@0.14 react-dom@0.14 react-addons-test-utils@0.14",
    "react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15",
    "pretest": "npm run --silent lint",
    "tests-only": "npm run mocha --silent test",
    "tests-karma": "karma start",
    "test": "npm run tests-only && npm run tests-karma",
    "storybook": "start-storybook -p 9001 -s ./public",
    "tag": "git tag v$npm_package_version",
    "gh-pages:clean": "rimraf _gh-pages",
    "gh-pages:build": "$(npm bin)/build-storybook -o _gh-pages",
    "gh-pages:copy-public": "cp public/* _gh-pages/$1",
    "gh-pages:publish": "$(npm bin)/git-directory-deploy --directory _gh-pages",
    "gh-pages": "npm run gh-pages:clean && npm run gh-pages:build && npm run gh-pages:copy-public && npm run gh-pages:publish",
    "version:patch": "npm --no-git-tag-version version patch",
    "version:minor": "npm --no-git-tag-version version minor",
    "version:major": "npm --no-git-tag-version version major",
    "preversion": "npm run test && npm run check-changelog && npm run check-only-changelog-changed",
    "postversion": "git commit package.json -m \"Version $npm_package_version\" && npm run tag && git push && git push --tags && npm publish --registry=",
    "prepublish": "in-publish && safe-publish-latest && npm run build || not-in-publish",
    "postpublish": "npm run gh-pages",
    "check-changelog": "expr $(git status --porcelain 2>/dev/null| grep \"^\\s*M.*\" | wc -l) >/dev/null || (echo 'Please edit' && exit 1)",
    "check-only-changelog-changed": "(expr $(git status --porcelain 2>/dev/null| grep -v \"\" | wc -l) >/dev/null && echo 'Only may have uncommitted changes' && exit 1) || exit 0"


This boilerplate follow the rule of airbnb

suggested packages

command line options

npm install --registry= --loglevel=silly


  • [12 - Publishing npm packages npm Documentation](