1. System environment
1. System version: Windows 11 Home Edition 64-bit 21H2
2. Node.js: node-v16.13.2-x64.msi
2. Operation steps
1. Download the Node.js version required by the corresponding system. The Node.js official website address is https://nodejs.org/zh-cn/
*Xiaobai can directly click to download, and the official website will automatically match the most suitable version for the current system.
2. Select the installation directory
3. Configure system environment variables
4. Debug npm
3. Download and install Node.js
1. Introduction to Node.js
- node.js is a JavaScript project management tool, similar in function to maven in java or pip in python.
- NPM (node package manager) is a package management and distribution tool for node.js.
- The new version of node.js integrates npm, so there is no need to install npm after installing node.js.
2. Download node.js
- This tutorial uses the installation package node-v16.13.2-x64.msi
- Enter the node.js official website and download the recommended node.js installation package
- If the current platform cannot be recognized, you can go to the download page to manually select the version to download
3. Install node.js
- Open the installation package node-v16.13.2-x64.msi and click Next.
- Agree to the terms of use and click Next.
- Modify the installation path
- Select the features that need to be installed, remember to select Add to Path, and then click Next.
- Select optional features as required and click Next.
- Click Install and perform administrator authorization in the pop-up window.
- Click Finish to complete the installation.
- If the optional features are checked in step 5, the following pop-up window will appear after the installation is complete.
Fourth, the installation is complete and tested
1. Check node and npm versions
Use the following command on the command line to check the version of node and npm.
node -v
npm -v
*Try not to use PowerShell, PowerShell is currently unstable and may report errors.
2. Node.js directory view
*5. System environment variable configuration
This step will customize the cache directory and global dependency directory of npm, so this step is optional.
1. Create a cache folder and a global dependency folder
Create two new folders in ideal locations: node_cache and node_global.
2. Use the command line to modify the npm configuration
2.1 Modify npm configuration
Open the command line (recommended) or PowerShell as an administrator, and enter the following statement to modify the npm configuration.
npm config set prefix "D:\nodejs\node_global"
npm config set cache "D:\nodejs\node_cache"
*The configuration path needs to be changed to your own
2.2 Check configuration npm configuration file
Open the .npmrc file in the C:\Users\username directory to check whether it is consistent with the configuration just now.
2.3 Modify user variables
Enter the system variable configuration, configure the Path variable in the user variable , and add a new variable below . Do not change other variable values in Path.C:\Users\username\AppData\Roaming\npm
D:\XXXX\nodejs\node_global
2.4 Modify system variables
Add a system variable in System VariablesNODE_PATH
and set the value to D:\XX\nodejs\node_global\node_modules
. Add a new value to
Path of the system variableD:\XX\nodejs\node_global\node_modules
. Do not change other variable values in Path.
Six, the use of npm
6.1 Install plugins using npm
Use the following command to create-react-app
install the plug-in into the global library. After execution, open the global directory to see the plug-in. --save
command can add dependencies to the package.json file.
npm install -g --save create-react-app
If it is only used temporarily, it does not need to be installed in the global library, just remove the -g parameter.
6.2 Use npm to uninstall plugins
Use the following command to uninstall the specified plugin, eg create-react-app
. If the specified plugin is installed in the global library, the -g parameter needs to be added.
npm uninstall create-react-app
npm uninstall -g create-react-app
6.3 Use npm to install the specified version of the plugin
- Use the following command to install ramda version 0.26.0.
npm install --save [email protected]
7. References
In the process of learning node, refer to the following literature/video materials