Common command sharing during development

This is the second day of my participation in Gwen Challenge

preface

NPM is a node. js package management tool, which is also one of the necessary management tools in actual project development. It can help us download some code modules written by others from nPMjs.com and install them in our project.

Some NPM commands that are commonly used in development

View the version of the current NPM

npm -v
// Return the current NPM version number
Copy the code

The help command

npm help [command]
Copy the code

Create the module (you can use -y here to skip the query phase and keep the default configuration)

npm init 
// Can also be used
npx create-thinkjs
Copy the code

install

This command installs a package, and its dependent packages, by getting the latest version of the package from the specified source address

Install the latest version of the package

npm install packagename
Copy the code

Installs the specified version of the package

npm install packagename @version
Copy the code

Install modules to development and production dependencies in the Dependencies field of your package.json file.

npm install packagename --save
Copy the code

Install module dependencies into the devDependencies field of your package.json file.

npm install packagename --save-dev
Copy the code

Uninstall modules in the current project

npm uninstall packagename
Copy the code

update

This command will update the currently installed module to the latest version

Update/upgrade modules in the current project

npm update [name]
Copy the code

Update/upgrade globally installed modules

npm update -global [package name]
Copy the code

link

The NPM link is used to establish a connection between a local project and a local NPM module so that module tests can be performed locally

Refer to the module

npm link [path]
Copy the code

Dereferencing modules

npm unlink [package]
Copy the code

View the packages installed for the current project

npm list
Copy the code

View the configuration of NPM

npm config list -l
Copy the code

NPM source

Gets the current NPM source

npm config get registrybash
Copy the code

Example Set the official NPM image source

npm config set registry https://registry.npmjs.org
Copy the code

Set the Taobao image source

npm config set registry https://registry.npm.taobao.org
Copy the code

You can also use CNPM to use Taobao source

npm install cnpm -g --registry=https://registry.nlark.com
Copy the code

View the NPM installation location

where npm
Copy the code

Package management

Publish is used to publish the current module to nPMjs.com, before which you need to apply for an account at nPMjs.com to publish

(note that if you are currently using is taobao source, you need to perform NPM config set registry to switch to the official image source https://registry.npmjs.org

The login

npm login
Copy the code

Publish a package

npm publish
Copy the code