Joldnine / joldnine.github.io

My github.io blog repo. https://joldnine.github.io
2 stars 1 forks source link

Npm: Notes #11

Open Joldnine opened 6 years ago

Joldnine commented 6 years ago

Here are some commonly used npm commands.

Install nodejs and npm (for Ubuntu)

  1. Download binaries from Nodejs download, eg. node-v6.11.5-linux-x64.tar.xz

  2. Extract to /home/{ ubuntu username }/Develop/Application

  3. Add export PATH=/home/{ ubuntu username }/Develop/Application/node-v6.11.5-linux-x64/bin:$PATH to the last line of the hiden file /home/{ ubuntu username }/.bashrc

  4. Execute source /home/{ ubuntu username }/.bashrc

  5. Execute node --version; npm --version It will show the versions if the installation is successful.

Get current global location of npm

$ npm config get prefix

Install a package

// global
$ npm i { package name } -g
// local
$ npm i { package name }
// update package.json
$ npm i { package name } -S

Install a package with the specified version

$ npm install axios@0.17.1

Update a package

$ npm update axios

List packages

// global
$ npm list -g
$ npm list -g --depth=0
// local
$ npm list
$ npm list --depth=0

Uninstall

$ npm uninstall { package name }

Use package.json file to manage the dependencies

$ npm init

Update all packages in package.json.

$ npm install npm-update-all -g
// under the directory of package.json
$ npm-update-all

Run npm for different directory

$ npm { command } --prefix { path/to/another/directory }

Registry config

Set registry $ npm config set registry { registry URL } Get current registry $ npm config get registry Actually, for npm config get/set, it simply gets/sets the key values in the config map, ie. registry is a key and its URL is its value in config map.