Summary of npm commands

1. Introduction to NPM instruction:

Keyword explanation: global installation, local installation, -save, -dev, i, -S, -D, -g

  • -g means global installation, no -g means local installation
  • i is short for install
  • npm i module_name -S 等价于 npm install module_name --save
  • npm i module_name -D 等价于 npm install module_name --save-dev
  • --Save means that when we install the module, we write it in the package.json file at the same time. --Now open the package.json file, we will see an additional dependencies field, which contains the installed module information.
  • What is –save-dev? It means that when the module is installed, it is written to package.json, but it is not written in dependencies, but in devDependencies.

What is the difference between devDependencies and dependencies?

  • dependencies: It is the dependency of the project when it is running, that is, the dependency is still needed after the program is online.
  • devDependencies, development dependencies, are the dependencies we need in the development process. For example, babel is only responsible for converting es6+ to es5. After the conversion is completed, we only need the converted code. When it goes online, directly deploy the converted code online without bebal. This is the development dependency and only works during development. , No need to go online. In fact, when we are developing with webpack, all the dependencies in its configuration file are development dependencies.

to sum up:

  • devDependencies are used for local environment development
  • User release environment
  • devDependencies are modules that will only depend on the development environment, and the production environment will not be included in the package. The packages that dependencies depend on can be used not only in the development environment, but also in the production environment. In fact, this sentence is the key point. According to this concept, it is easy to decide whether to use –save or –save-dev when installing modules.

2. Create:

//Guide you to create a package.json file, including name, version, author and other information

npm init 或 npm init -y

3. Installation:

//Global installation
npm install module name-g
//Local installation
npm install module name
//Install multiple
npm install modules at one time Module 1 Module 2 Module 3
//Install the development dependency package
npm install Module name--save-dev
/ /Install the runtime dependency package
npm install module name --save
//Install the module to the specified version
npm install module name@version number
//If you install to the latest version, you can use the following command
npm install module name@latest

Four, uninstall:

npm uninstall module name

Five, find:

npm search module name

Six, version view:

//View all released versions of the module
npm view module name versions
//View the latest version of the module
npm view module name version

Attachment:
npm installs the module globally, and XXX is not an internal or external command. Solution
After installing express globally from the express website directly following the command line, the express command cannot be executed, and the command line cannot be recognized in cmd. Basically it can be judged that the environment variable configuration is not done here.

  1. Uninstall nodejs and reinstall
  2. First configure the storage path and cache path of npm's global module (if installed by default, it will be on the C drive, and the following input can be used directly in the command line. For custom installation, change it to the path you set yourself)
    npm config set prefix "C:\Program Files\nodejs\node_global"
    npm config set cache "C:\Program Files\nodejs\node_cache"

Configure environment variables

Open the computer, system properties-advanced system settings-environment variables; under system variables, create a new NODE_PATH, the value is C:\Program Files (x86)\nodejs\node_global (global path,) and "%NODE_PATH%" to path Just after the variable value.
Then after executing epxress on the command line, some prompts will appear, indicating success.

Guess you like

Origin blog.csdn.net/weixin_40599109/article/details/109224602