Get the configuration and multi-version control of Nodejs
1. What is Node.js
JavaScript can also be run without the browser environment, as long as there is a JavaScript engine.
Node.js is a JavaScript operating environment based on the Chrome V8 engine: that is, Node.js has Chrome's V8 engine built in, and JavaScript programs can be run directly in the Node.js environment.
Writing JavaScript in Node.js is basically the same as writing JavaScript in the Chrome browser. What's the difference?
Node.js does not have a browser API, namely document, window, etc.
Many Node.js-specific API s have been added, such as file system, process, and http functions.
To put it bluntly: Node is JavaScrip t running on the server.
2. What is npm
npm:
The full name is Node Package Manager, which is a NodeJS package management and distribution tool, which has become an unofficial standard for releasing Node modules (packages).
3. The relationship between node and npm
When downloading and installing node, npm is also installed. In fact, npm is a set of package management tools built into node.js. Then we can use the npm install ... command to download the toolkit (dependency) we need.
4. Install Node.js separately
4.1 Uninstall a single Node.js
- uninstall node itself, delete the nodejs directory. When you click Uninstall, the nodejs directory will be deleted automatically, but just in case, you can email to open the file installation directory before uninstalling.
- Delete the environment variable configuration modified by node.js
4.2 Install a single Node.js
-
Go to the official website to download the new version, http://nodejs.cn/download/
Official website: https://nodejs.org/en/
Chinese website: http://nodejs.cn/
LTS: Long Term Support Release
Current: latest version
- Select the installation directory, next on the line
- Check if the installation is successful
- Open cmd In the command line window, enter node --version, if the correct version number appears, the installation is complete. If not, you need to configure the environment variable again.
- Use cmd to enter: node -v can successfully display the version number of node, which means the installation is successful
5.node version control tool nvm
If you are sure that your node version needs or is often changed, it is recommended to install the node version control tool to facilitate better compatible development
Download address: https://github.com/coreybutler/nvm-windows/releases
5.1 Installation
Note that you must write the nodejs version downloaded separately before installation
Install
nvm installation address
The nodejs installation address path must not contain spaces and Chinese
5.2 Configuration
Set download mirror
You need to go to the nvm installation path to find the nvm/setting file, add node and npm Taobao images, the default international installation and download will be very slow
node_mirror: https://npm.taobao.org/mirrors/node/ npm_mirror: https://npm.taobao.org/mirrors/npm/
At this point, nvm is installed
Enter nvm in the command window, if there is a prompt, it means the installation is successful
5.3 Install different versions of node
Check out the downloadable releases:
- command nvm list available
download:
- Command: nvm install version number
switch between different versions of node
- Command: nvm use version number
View the node version used by the current system
Command: node -v
Check which versions you have downloaded
Command: nvm list installed
In fact, the one with * in front of the picture is the current version
5.4 View the required node version in the Vue project
When working on a project. The version of nodejs used by different projects may be different. We can see in the configuration file:
Due to the difference between the nodejs version and the npm version. causing the project to fail to run. So we need to use the tool nvm!
5.5 Common commands
nvm off // Disable node.js version management (doesn't uninstall anything) nvm on // Enable node.js version management nvm install <version> // The named version of the installed node.js is the version number For example: nvm install 8.12.0 nvm uninstall <version> // Uninstall node.js is the command to uninstall the specified version of nodejs, when the installation fails to uninstall use nvm ls // Show all installed node.js versions nvm list available // Show all versions of node.js that can be installed nvm use <version> // Switch to using the specified nodejs version nvm v // show nvm version nvm install stable // Install the latest stable version
nvm Command line operation command 1,nvm nvm list is to find all the node Version - nvm list View installed versions - nvm list installed View installed versions - nvm list available View network-installable versions 2,nvm install install latest version nvm 3,nvm use <version> ## Switch to use the specified version node 4,nvm ls list all versions 5,nvm current show current version 6,nvm alias <name> <version> ## Add an alias to a different version number 7,nvm unalias <name> ## Delete defined aliases 8,nvm reinstall-packages <version> ## In the current version of the node environment, re-install the npm package with the specified version number globally 9,nvm on Open nodejs control 10,nvm off closure nodejs control 11,nvm proxy View settings and proxy 12,nvm node_mirror [url] set or view setting.txt middle node_mirror,If not set the default is https://nodejs.org/dist/ nvm npm_mirror [url] set or view setting.txt middle npm_mirror,If not set, the default is: https://github.com/npm/npm/archive/. 13,nvm uninstall <version> Uninstall the specified version 14,nvm use [version] [arch] Toggle made node version and bitness 15,nvm root [path] settings and view root path 16,nvm version view current version
5.4 Uninstall version control tool
i.e. uninstall nvm
Uninstall nvm, go to the official website to download the latest version again, remember to uninstall completely, the specific uninstall steps are as follows
step one:
- First, manually delete the nvm installation path, delete the entire folder
Step two:
- Then go to delete the environment variable
-
Right-click My Computer, click Properties, and select Advanced System Settings as shown in the figure.
-
Click on Environment Variables
-
Then delete nvm related system variables
-
There are also related configurations under the path, do not move the others
System and personal must be deleted! ! ! ! ! two path s
So far nvm is completely deleted
Then go to the official website to download the nvm compressed package and reinstall it.
6. Configure npm
Change the global default C drive installation path of npm
- Create two new folders node_cache and node_global under the custom installation directory
- configuration node environment variable
- Increase environment variable The content of NODE_PATH configuration is node_modules path
- Check the installation status of npm
- Configure npm's cache path and global path
npm config set prefix "D:\node\node_global" npm config set cache "D:\node\node_cache"
- Configure npm download mirror
npm Change the address to Taobao Mirror: npm config set registry https://registry.npm.taobao.org
-
View the configuration of npm
npm config ls
You can use -g to test it, download something and see if it is downloaded to the global path
Notice:
Note: Be sure not to delete the .npmrc file under C:\Users{account}\. If you delete it, the default global download path you changed before will be invalid.
- npm configuration file: