Install multiple versions of Node under Windows
2019-06-24 updated: 2019-06-29 00:00
Author: Ghost girl
Objective: This paper aims to give xiaobai
- How to select the version of Node.js suitable for your development needs (click direct);
- How to uninstall Node and NPM correctly on Windows (click Direct);
How to install and manage multiple versions of Node.js on Windows.
(Click on the direct);
- Uninstall the node
- Install the node
Introduction: In this article, you can quickly learn what Node.js is; Understand node.js releases; Node version management scheme and the differences between the schemes; N, NVM, NVMW, and NVM-Windows.
Note: this article sorted out and compiled some knowledge related to node installation, only for reference, improper description of the place, please comment correct, also look forward to your participation in writing
Status: Updated, to be improved
[TOC]
Node. Js’s official website
- Official English version
- Official Chinese version
- Other:
- nodejs.cn/
The relationship between JavaScript, Node.js and V8
For developers who know Node, we all know that Node is a Runtime environment based on the Chrome V8 engine that enables JavaScript to run on the server. On the one hand, it provides a variety of callable apis, such as reading and writing files, network requests, system information, etc. On the other hand, because the CPU executes machine code, it is also responsible for interpreting JavaScript code into machine instruction sequences, which the V8 engine does.
A, node. Js
Node.js is a JavaScript runtime environment based on Chrome V8 engine. Node.js uses an event-driven, non-blocking I/O model, making it lightweight and efficient. Node.js package manager NPM is the world’s largest open source library ecosystem.
1.1 What is Node.js
- It is a Javascript runtime environment
- Rely on Chrome V8 for code interpretation
- Lightweight and scalable, suitable for real-time data interaction applications
Node.js is a JS runtime environment (which simply means it can parse and execute JS code) : not a language/library/framework. Node.js uses JavaScript programming and runs on the JavaScript engine (Chrome V8). Unlike other languages, it runs on the server side (Apache,Naginx, IIS Tomcat) and other HTTP servers. It doesn’t have to be built on top of any server software. The design concept of Node.js is very different from the classical LAMP architecture (LAMP=Linux + Apache+ Mysql+ PHP) and can provide great scalability.
- (1) JavaScript in Node.js does not have BOM, DOM, only EcmaScript (basic syntax), because the server does not manipulate the page
- (2) Node provides some server-side apis for JS (file reading and writing, network service building, network communication, HTTP server, etc.) in the javascript execution environment.
1.2 the node. Js features
- Node.js features (addressing server performance bottlenecks) :
- Single thread
- Non-blocking I/O (simply asynchronous)
- event-driven
- cross-platform
First of all, if you want to understand node.js’s features you probably need to understand js: synchronous & asynchronous, thread & process, event loops, macro tasks, micro tasks
Single thread
In server-side languages such as Java, PHP, or.NET, a new thread is created for each client connection. Each thread consumes about 2MB of memory. In other words, the maximum number of users that can be connected to a server with 8GB of memory is about 4000. To enable Web applications to support more users, the number of servers needs to increase, and the hardware cost of Web applications certainly goes up.
Instead of creating a new thread for each client connection, Node.js uses only one thread. When a user connects, an internal event is triggered, making Node.js programs macroscopically parallel through non-blocking I/O, event-driven mechanisms. With Node.js, a server with 8GB of ram, it can handle connections from over 40,000 users at the same time. In addition, the benefit of single threading is that the operating system completely eliminates the overhead of thread creation and destruction, and the single-threaded CPU utilization is always 100 percent. The downside is that one user crashes the thread, the entire service crashes, and everyone else crashes.
A comparison of multithreading and single threading:
That is, a single thread can also cause “concurrency” on a macro level.
The single thread itself has the following weaknesses:
Node is not a single-threaded architecture strictly speaking, Node also has a certain number of I/O threads. These I/O threads are handled by the underlying LIbuv. This means that Node is still multi-threaded when accessing system I/O. For specific operations such as file reading, SQL query and network request, Node still uses multi-threading to ensure the efficiency of Node processing.
In order to cope with the CPU utilization problem of single thread, Node adopts the multi-process architecture, which is also known as the master-worker mode, also known as the master-slave mode. As shown in the following figure, this typical distributed architecture for parallel processing services has good scalability and stability. Each process requires at least 30 milliseconds of startup time and at least 10MB of memory. The fork() process has some overhead, but it can improve multi-core CPU utilization. While this is important in a world where cpus are mostly multicolorized, it is important to recognize that Node is already capable of dealing with large concurrency in an event-driven manner on a single thread, starting multiple processes only to maximize CPU resources.
In the master-worker mode of Node, the Master process communicates with the Worker process through message passing rather than sharing or directly operating resources. After the Worker process is created through fork(), an IPC channel will be created between the Master process and the Worker process. Node officially provides the Cluster module to manage processes. For details, see Cluster.
As for the robustness of the application, we can also adopt the master-worker mode mentioned above, where the main process is only responsible for managing the Worker process and the specific business processing is done by the Worker process. Listening uncaughtException event in the Worker process can catch the unknown exception and then inform the main process. The main process recreates the worker process according to the policy or exits the main process directly. In this case, sufficient log information must be provided in the code to generate alarms through log monitoring tasks.
Non-blocking I/O Non-blocking I/O
For example, when accessing a database to retrieve data, it takes a while. In traditional single-threaded processing, after the database access code has been executed, the entire thread will pause and wait for the database to return the results before executing the subsequent code. In other words, I/O blocks the execution of code, greatly reducing the efficiency of program execution.
Because of the non-blocking I/O mechanism in Node.js, the code that accesses the database is immediately switched to the following code, and the code that returns the result from the database is placed in the callback function (event queue), thus improving the execution efficiency of the program.
When an I/O completes, the thread that performed the I/O operation is notified as an event, and the thread executes the callback function of the event. To handle asynchronous I/O, a thread must have an even loop that continuously checks for unprocessed events and processes them in turn.
In blocking mode, a thread can only handle one task, and multithreading is required to improve throughput. In non-blocking mode, a single thread is always performing computations, and the CPU core utilization of that single thread is always 100%. So this is a particularly philosophical solution: instead of having too many people, but too many of them idle; It’s better to die alone, working to death.
Event-driven event-driven
In Node, events are triggered when a client requests to establish a connection, submit data, etc. In Node, only one event callback can be executed at a time, but in the middle of executing one event callback, you can switch to another event (for example, a new user has connected) and then return to the callback of the original event. This is called the “event loop” mechanism.
Node.js is C++ (V8 is also written in C++). Nearly half of the underlying code is devoted to building event queues and callback function queues. Using event-driven to complete the task scheduling of the server, this is a genius. The dance on the head of a pin, with one thread, takes on the task of handling a very large number of tasks.
Relationships between Node.js features
Single thread, single thread benefits, reduced memory overhead, operating system memory page feed.
If something comes in, but it’s blocked by I/O, so the thread is blocked.
Non-blocking I/O, which does not wait for an I/O statement to end but executes subsequent statements.
Will non-blocking solve the problem? For example, when the I/O callback of Xiao Gang is completed, what should I do?
Event mechanism, event loop, whether new user request, or old user I/O completion, will be added to the event loop in the form of events, waiting for scheduling.
It is said that there are three characteristics, but in fact there is only one characteristic. It is impossible to live without anyone. Node.js is a lot like a penny-pincher restaurateur, employing only one waiter to serve many people. As a result, more efficient than many waiters. All I/O in Node.js is asynchronous, with callback function after callback function.
cross-platform
When Node was first released, it only ran on Linux, but it has since been changed architecturally to introduce a layer of Libuv between Node and the operating system to make it cross-platform. Cross-platform means PC, mobile, Web/H5
1.3 Advantages, disadvantages and solutions of Using Node.js
advantages
The features of Node.js are also its advantages, which can be summed up as
- High concurrency (most important advantage)
- Suitable for I/O intensive applications
High Concurrency is one of the most important things to consider when designing an Internet distributed system architecture. It usually refers to the idea of designing a system that can handle many requests in parallel.
To learn more about high concurrency (), please click the following link:
-
What is high concurrency, explain in detail
-
Do you know what high concurrency is? Make sure you understand the saying (recommended reading)
disadvantages
This is the nature of Node.js, so it has a lot of disadvantages
1. Not suitable for CPU intensive applications
;- Cpu-intensive applications pose major challenges to Node: Due to single-threaded JavaScript, if there is a long running computation (such as a large loop), the CPU time slice cannot be released and subsequent I/ OS cannot be initiated.
- Solution: Decompose large computing tasks into several small tasks, so that computing can be released timely and not block the initiation of I/O calls;
2. Only single-core CPU is supported, and CPU cannot be fully utilized
3. Low reliability. Once a link of the code crashes, the whole system crashes
- Cause: Single process, single thread
- Solution: (1) Nginx reverse proxy, load balancing, open multiple processes, bind multiple ports; (2) Open multiple processes to monitor the same port, using the Cluster module;
4, open source component library quality is uneven, update fast, downward incompatible
5. Debug is not convenient. There is no stack trace for errors
1.4 Domains suitable for Node
- The Internet
- E-commerce
- Payment processing
- Social media
- Real-time service
- The media
- Enterprise Web Services
- . See node.js application scenarios below for more information
What kind of applications should 1.5 Node.js be used for?
Node.js is good at I/O and not good at computation, because node is good at scheduling tasks. If your business is doing a lot of CPU computation, it’s essentially blocking the single thread. Node is ideal for applications that need to handle a large number of concurrent I/O (asynchronous operations), but don’t need very complex processing inside the application before issuing a response to the client. Node.js is also ideal for working with Web Socker to develop long-connected, real-time interactive applications. Such as:
- User form favorites
- The test system
- The chat room
- Direct seeding
- Json API (used by the foreground Angular)
If you understand the features and principles of event queuing, stack execution, and async execution of JS in-memory applications, you can easily determine when to use Node.js for development. Answer to the above question, if to perform a stack and the event queue to analysis, is that the thread must first be processed to perform tasks in the stack, can put the event queue team first events in the execution stack, such as after completion of the task, go to the event queue in the team the first task in the execution stack, cycling, till the event queue is empty. If there are many tasks on the execution stack before sending an asynchronous request, the event queue will have to queue for a long time, which is not suitable for Node development. In fact, most projects will use Node.js.
1.6 Suitable for Node.js scenarios
Now that we understand what kind of applications Node.js is suitable for, let’s take a look at some scenarios that are suitable for NodeJS:
RESTful API
This is the ideal scenario for NodeJS, which can handle tens of thousands of connections without much logic of its own. You just need to request the API and organize the data back. It’s essentially just looking up some values from some database and putting them together into a response. Because the response is a small amount of text and the inbound request is a small amount of text, the traffic is low and a single machine can handle the API requirements of even the busiest companies.
Unify the UI layer of Web applications
In the current MVC architecture, in a sense, Web development has two UI layers, one in the browser that we eventually see, and the other on the server side that generates and concatenates pages. There is no discussion of whether this architecture is good or bad, but there is another practice, service-oriented architecture, that does a better separation of dependencies at the front and back ends. If all of the critical business logic is encapsulated as REST calls, that means you only need to worry about building concrete applications with those REST interfaces at the top. Back-end programmers don’t care how data gets passed from one page to another, nor do they care whether user data updates are retrieved asynchronously through Ajax or through page refreshes.
Application of a large number of Ajax requests
For personalization applications, each user sees a different page, the cache fails, Ajax requests need to be made when the page loads, and NodeJS can respond to a large number of concurrent requests. In summary, NodeJS is suitable for high concurrency, I/O intensive, small business logic scenarios.
Examples of node.js usage scenarios:
- Websites (e.g. Express/KOA, etc.)
- Im Instant chat (socket.io)
- API (Mobile, PC, H5)
- HTTP Proxy (Taobao, Qunar, Tencent, Baidu)
- Front-end build tools (grunt/gulp/bower/webpack fis3 /…).
- Write operating system (NodeOS)
- Cross-platform packaging tools (electron, NNW. Js on PC, such as dingding PC client, wechat small program IDE, wechat client, mobile cordova, the old Phonegap, and the more famous ionicframework for one-stop development)
- Command-line tools (e.g. Cordova, shell.js)
- Reverse proxy (such as anyProxy, node-http-proxy)
- Editor Atom, VSCode, etc
It can be said that all the software you can see and use at present has Node.js. Most of the most popular software writing methods are based on Node.js, such as PC client Luin/Medis using electron packaging and React+Redux. In the future, Node.js will be widely used. See more at github.com/sindresorhu… .
1.7 Not suitable for Node.js scenarios
- 1. Computationally intensive applications
- 2. Single-user multi-task programs
- 3. Logically complex transactions
- Unicode and internationalization
Why install multiple versions of Node.js
2.1 Talk about installing multiple versions of Node.js
First, before answering this question, it is advisable to take a look at the history of Node.js, but now you don’t need to worry about multiple installs of this type, or whether to develop with io.js or Node.js. Because IO. Js and Node. js are now merged, check out the Reconciliation Proposal for details. However, it’s important to understand why you should consider installing multiple versions of Node.js before merging. Before the merger of io.js and Node.js, we usually use:
- Community edition – IO. Js
- Website version — node. Js
Both are based on the V8 engine. For now, we only need to consider whether the installed version is odd or even, LTS or Current. See section 2.2 for reasons for installing multiple versions.
Multiple versions are:
-
1. Install multiple versions of Node.js before merging IO. Because IO. Js has many new features and Node.js is a stable version, many new features are not supported by Node.js. The community edition updates very quickly and has many new features, but many project environments do not support these new features, so sometimes you need to switch between IO. Js and Node.js and install IO.
-
2. Now, we just need to consider whether the installed version is odd or even, LTS version or Current version. Generally speaking, we install two versions recommended by the official website: LTS version and Current version.
-
3. Multiple versions The value can be two or more versions
2.2 the IO. Js
IO. Js (JavaScript I/O) is a new branch of Node.js compatible with the NPM platform. The core developers of Node.js introduce more ES6 features on top of Node.js, and it aims to provide faster and predictable release cycles.
2.2.1 IO. Js target
- Continuous integration
- 100% test pass as normal
- A strict Semver-Compliant version
- All rights reserved by submitter and out of company control
- Transparent consensus-seeking regulation.
- weekly
- Support V8 version
- Active development
- Predictable path
- Since io.js and Node.js have been merged, io.js is already called Node.js. So the official website of io.js and Node.js is the same.
2.3 Reasons for Installing multiple Versions
It’s not uncommon in our daily development to have several projects on hand, each with different requirements, which in turn must rely on different versions of the NodeJS runtime environment
LTS represents a revised and improved version that includes the latest features of the Node.js platform. Sometimes our project will need an environment that doesn’t support node’s new features, so you’ll need to switch to LTS, or if you want to work on new features at the same time, you’ll need current.
Understand node.js releases
Node.js releases tend to jump over time to ensure compatibility is close, not compatibility and new features, which explains why node.js releases seem to jump so fast
More and more developers are choosing Node.js as their development platform. However, because there are so many versions of Node.js, it becomes a problem for novices to choose which version to choose and how to choose it. This article briefly introduces the release rules of Node.js as a reference for beginners to choose a version. Note that the introduction of this article is intended to help address only one of the first issues you will face when choosing a version, not the whole package
3.1 Node.js Release process
You can go to the official website about the release of the information, in order to understand the convenience of the following is my version of today (2019-6-24) on the official website overview information chart:
Note that the following is the current flow and there may have been different approaches or exceptions to node.js evolution in the past. Here are some key points about the Node.js release process:
- A Major release (the Major change) is released every 6 months as the Current release
- Release Month:
An even-numbered version will be released in April
.Odd-numbered versions will be released in October
- Migrate one release to LTS every 12 months. Yes, only even versions (usually when the odd-numbered version is released later)
- LTS releases go through two phases: Active and Maintenance.
The Active period lasts for 18 months. It is mainly about periodically fixing bugs and incorporating important changes from other versions without changing compatibility
The Maintenance period is 12 months, only responsible for the revision of bugs and special emergency such as security problems or document updates
.
See section 3.5 of this article for more details on semver/Major/ version number naming rules. Or go to semver see semver introduce https://semver.org/lang/zh-CN/ in detail
3.2 Download from node. js official website
When users visit the official website of Node.js, the main download page they will encounter is as follows:
Or:
As you can see, there are two main versions recommended for download: 10.16.0 and 12.4.0, with the first number 10 or 12 representing the Major version number depending on the Semver version. See Section 3.5 of this article for more details on Semver /Major. Or go to semver see semver introduce https://semver.org/lang/zh-CN/ in detail
3.3 Differences between LTS and Current
- LTS — Long Term Support
- The Current LTS version is
The relative
Stable version, Current version is the beta version
Current represents the latest release (every 6 months), which can be an odd or even release. Because it is up to date, it includes the latest features of the Node.js platform.
LTS represents a version that is constantly being revised and improved.
At each moment, there is only one Current version, three LTS versions, and two LTS-Active versions.
The LTS version given on node.js website is always the latest version of LTS (currently 10.16.0), which is active according to the release schedule and we can see that the MINOR version is in the process of upgrading.
3.4 LTS (Long Term Support)
3.4.1 Node.js LTS plan
After node.js core is merged with IO. Js, in order to ensure stable and orderly release and enable developers to reasonably arrange upgrades, Long Term Support (LTS) is used to plan the release cycle. The first LTS release, V4, was released in October 2015. Under this plan, node.js versions are snapshots of the master branch that have been stabilized at a given time. When the time is up, the stable parts of the master branch will be consolidated and a new version will be released. Therefore, node.js releases are based on the passage of time. This is why versions of Node.js seem to jump so quickly (as opposed to “Oh, we’ve got so many tricks we can release new versions!” It’s “Oh, April is coming, let’s go through all the big tips we’ve got and see what’s stable enough to add, even if it’s not that big…” ).
It is worth mentioning that the current evergreen browser/mainstream JavaScript engine /ECMAScript standard /C++ standard also uses similar principles to release stable features from the trunk based on time span.
Each LTS is given a code name, which is taken from the periodic table and sorted alphabetically to pick the right one.
- The code name for V4 is Argon
- The code name for V6 is Boron
- The V8 is code-named Carbon.
- V10 was named Dubnium, du
Node.js version naming rules follow semver Semantic Versioning. The version number is divided into three parts. See Section 3.5 of this article for more details about Semver. https://semver.org/lang/zh-CN/ to semver see detailed semver introduction,
- The first number (semver-major) increases, indicating incompatible changes;
- The second digit (semver-minor) increases to indicate that there are new features that remain compatible;
- The third digit (semver-patch) increases, indicating changes that have been made while maintaining compatibility and features, such as bug fixes or documentation improvements.
There are pros and cons to this naming rule, which I won’t go into here, but there are some inconsistencies that make node.js naming exceptions. For example, security updates are semver-minor in order to be able to update to all major versions, even if they cause incompatibility. https://semver.org/lang/zh-CN/ to semver see detailed semver introduction,
3.4.2 The life of an LTS
Detailed please go to the node. Js Release of git branch for more information on LTS on https://github.com/nodejs/Release
Current (1.4 ~ 1.10)
-
LTS Current: April to October in the first year
- Node.js currently branches off from master in April each year, collecting enough stable features to release an even-numbered version of a major (such as V6.0.0) as an alternative to the next LTS. For the six months from April to October of that year, the even-numbered version is called “current” (e.g. V6.0.0 “current”). Following community feedback, the minor version will continue to grow as bugs are fixed, new features are added, improvements continue to be made, and some improvements that are too incompatible may be removed. Developers can use this time to test their applications offline with the candidate LTS release and report compatibility issues and bugs to node.js developers.
The active (1.10 ~ 3.4)
-
LTS Active: October of year 1 to April of year 3
- By October of that year, the even-numbered version will become LTS (for example, V6.9.0 “LTS”), at which point it will also be called “Active LTS”. During the next 18 months of active, there will be almost no incompatible changes to this release, and no major updates to dependencies other than security-related OpenSSL (such as V8). During this time developers can upgrade online Node.js to this stable LTS version and iterate with new features of Node.js.
Maintenance (3.4 ~ 4.4)
-
LTS Maintenance: April of year 3 to April of year 4
- After an 18-month active period, in April of the third year, the release will enter its final 12-month maintenance period, with only security updates and bug fixes. Since Node.js releases an LTS every October, a new Active LTS is born on two-thirds of the nodes in the active phase of this release. (Currently, with six months of ACTIVE V4 LTS remaining, V6 LTS Active release point). By the time its active period ends, developers will have six months to transition to the next Active LTS. Even if the developer update progress is slow, there are still 12 months of maintenance time, hurry up to upgrade. After 12 months, the LTS will end its life without any updates. So, each even number version has a 3-year life.
3.4.3 How does this LTS correspond to the node.js source code?
First, node.js’s Github Repo has a master branch to which most commits are made via PR. Commits are labeled semver-major or semver-Minor, depending on whether they change compatibility or introduce new features.
Before April of each year, node.js intercepts a new branch from the master branch. If this is V6, this branch is called V6.x-staging. Any subsequent changes related to this LTS/changes intended to enter this LTS, such as bug fixes, will still be submitted to the master with a tag lTS-watch-v6.x. After being merged into master, these changes are picked out by the publishing people and consolidated to V6.x-staging.
At some point in April, when the first version of V6 is ready to be released, the release team will create a v6.x branch that can pick out changes from v6.x-staging and merge them. From April to October, all changes to V6, whether minor or patch, are still submitted to master and then sorted out to V6.x-staging, and then to V6.x at release time. This way, the master always keeps the latest changes. V6.x-staging holds v6.x LTS changes. V6.x holds v6.x LTS changes at any v6 release. These version-related branches are left untouched by developers other than those responsible for the branch.
3.5 Semver
What is a Semver
To semver see semver introduce https://semver.org/lang/zh-CN/ in detail
Sem+ver, Sem means Semantic, ver means Version. Semver represents a version naming method that reflects the meaning of certain version changes. The current term Semver generally refers to the version specification developed by Semver.org. The basic requirements are as follows: The version number is in the format of major.minor. PATCH, which consists of three parts. The meanings of adding values of each part are as follows:
- MAJOR: SOFTWARE API changes
- MINOR: Modify or add functionality, but keep backward compatibility (API unchanged)
- PATCH: a PATCH that fixes errors
How do developers choose node.js versions
- The latest version is recommended if you need to try the latest ES specification
- For project use, long-term versions are recommended to maintain stability
Generally speaking, we install the two versions recommended by the official website: LTS version and Current version as follows
4.1 Stability seeking — LTS
For stable Node.js app developers, you only need to upgrade online every October when a version becomes active LTS, i.e. upgrade major every 12 months. Each upgrade has a life of 18 months + 12 months. Don’t worry too much about compatibility with minor and Patch in between.
The current recommendation is to complete an online upgrade within 12 months of an Active LTS release (since the next Active LTS will be released after 12 months). If you fall behind, compromise to 18 months, or before the end of the ACTIVE LTS period. After that, the upgrade should be completed at least 30 months before the end of the version’s life or there will be no security updates.
If you are worried about the compatibility problems encountered by direct upgrade, you can test and prepare for the upgrade offline in advance when the even-numbered version comes out in April every year, and feedback the problems to the community (of course, if you are not available, you do not need to take care of this step), and keep following up, and then upgrade the online version in October. So you have a 12 month major up and down the line, but at different points in time. Although there are more compatibility problems that need to be followed up offline, they can also make their compatibility needs taken care of by the community through feedback.
4.2 Enthusiasm for trying new features — current
For those keen to try out new features, or experimental projects that aren’t in production, try the odd Major releases released every October. Each odd-numbered version will only be maintained for 8 months and won’t have the same compatibility guarantees as LTS, but node.js developers will use this version to prepare for the next LTS, so it will be more adventurous. For example, more frequent V8 updates (meaning more new ECMAScript feature implementations and performance optimizations).
As a result, developers using V4.x online are now ready to upgrade to v6.x. If your online app is running a pre-launch version of LTS, such as V0.12.x, you’d better upgrade to V4.x or above as there will not be any security updates for V0.12.x after December 2016, especially earlier versions. Mainly OpenSSL vulnerabilities will not be fixed and these applications will be exposed to various security risks. Once you upgrade to V4.x or higher, future upgrades will be relatively easy, just remember to keep up with Minor or Patch, or if you’re lazy, just focus on security updates.
5. Talk about installing or managing Node.js on different platforms
You can check out this article on the website for a start:
- (Chinese version) Install Nodejs using the package manager
- Install Nodejs through package manager
In this article on the website, you can see how to install and manage Node.js on different platforms
Vi. Multi-version management scheme
First look, Taobao front end team FED fahai released in 2015, management node version, choose NVM or N? If you can’t access it in Google Chrome, please switch to another browser.
6.1 N, NVM, NVMW, and NVM-Windows
The most common options for managing Node versions are as follows:
- n
- nvm
- nvmw
- nvm-windows
To learn more n information, you can click to view TJ n, written in the great god in making or https://www.npmjs.com/package/n;
6.1.1 n
- N Windows is not supported
- N No subshells, no config file Settings, no complex apis.
- The n command exists as a node module
- N The global node/ NPM directory is shared between different node versions
N Install the Node-based NPM module
The NPM package that requires a global installation (after node is installed on the computer, thenInstall NPM globally
To install n by using NPM. >> + N cannot be used if node is not installed;
6.1.2 NVM
NVM here is not NVM-Windows, but simply NVM for Mac/Linux, even though NVM-Windows is also referred to as NVM by many developers, nVM-Windows is not a simple port of NVM, and they have nothing to do with it.
NVM only works on Mac/Linux.
NVM does not generally support Windows systems, but may support WLS (the Linux subsystem under Windows). You can check out the NVM website for important tips
NVM is an external shell script that is independent of Node/NPM and is a separate package
NVM is independent of the Node environment and can be used without node installed
The global modules of NVM exist in their respective version sandboxes and need to be re-installed after switching versions, and there is no conflict between different versions
To learn more about WLS, check out the following links:
WSL (Linux subsystem under Windows) (Baidu Encyclopedia);
A brief introduction and installation of WSL(Linux subsystem on Windows);
Also 6.1.3 NVMW
SORRY, NVMW is no longer maintained. If someone wants to keep, contact me by email or Twitter.Copy the code
Use NVM-Windows. NVMW is not covered in detail here
- NVMW supports only Windows
- A prerequisite forBefore installing NVMW, you must install:
- git
- Python 2.7 + only if you need Node < 0.8
6.1.4 NVM – Windows
- Nvm-windows is a command line tool
- Nvm-windows is not a simple port of NVM, nor are they related.
- Nvm-windows is often referred to as NVM for short, but use the nVM-Windows name whenever possible
- Nvm-windows When switching node versions, NPM modules are not shared between different node versions.
- Before installing NVM-Windows:
- Uninstall any existing version of Node.js installed on your computer
- Delete any existing NodeJS installation directories that may remain (for example, “C:\Program Files\nodejs”)
- Remove the existing NPM installation location (for example. C:\Users\AppData\ NPM “), in order to correctly use the NVM installation location
- This is required after the nVM-Windows installation is complete
- Must be
each
Reinstalling global utilities such as gulp/webpack on installed versions of Node requires reinstalling all applications or command lines previously installed on node. If you only use one version of Node, you can reinstall it, but if you switch to another version of Node and want to use the application from the previous version of Node, you need to reinstall it
The following paragraphs are excerpted from the official website for easy comprehension:
-
Please note that any global NPM modules you may install will not be shared between different versions of Node.js that you have installed. In addition, some NPM modules may not be supported in the version of Node you are using, so be aware of your environment when working.
-
Before you can install NVM-Windows for Windows, you need to uninstall any existing versions of Node.js installed on your computer. Also delete any existing NodeJS installation directories that may remain (for example, "C:\Program Files\nodejs"). Nvm-windows generates links that do not overwrite existing (or even empty) installation directories.
-
You should also remove the existing NPM installation location (for example. C:\Users\AppData\ NPM "), in order to correctly use the NVM installation location. Once the installation is complete, you must reinstall the global utility (such as gulp) for each installed version of Node:
nvm use 4.4. 0
npm install gulp-cli -g
nvm use 0.1033.
npm install gulp-cli -g
Copy the code
Attention please!! From the website:
I’ve done some work to make this project available on all operating systems. The only reason it’s been so slow to release is anticipation of an explosion of new installers (chocolatey, homebrew, rpm, .deb, .msi, etc). I’ve partnered up with BitRock to simplify creation of some of these, but the BitRock installers don’t support all of these. I did some work to make the project available on all operating systems. The only reason it’s been so slow to launch is because of the number of new installers expected (chocolatey, homebrew, RPM,.deb,.msi, etc.). I worked with BitRock to simplify the creation of some of these, but the BitRock installer doesn’t support all of them.
The multilingual support for NVM-Window will not come until 2.0.0, when it will be a cross-platform version manager, or it will not be called NVM-Windows
6.2 Relationship between NVM and NVM-Windows
About using NVM or N? NVM (for Linux/ MAC) and NVM-Windows (for Windows) are commonly referred to as NVM or NVM. Nvm-windows is not a simple port of NVM, and they are not related in any way. These are two different projects. So, try to call them in a standard way. You can check it out on GitHub, which has the link below:
- nvm:github.com/nvm-sh/nvm
- Nvm-windows:github.com/coreybutler…
NVM commands can run in NVM-Windows. NVM commands can run in NVM-Windows.
-------- The differences between NVM and NVM-Windows are collected and summarized ~------
-------- more differences, waiting for your discovery, invite you to participate in writing ------
6.3 Differences between N and NVM and NVM-Windows (How to Select node Version Management)
6.3.1 About Supported Operating Systems
- Windows: NVM-Window, NVMW, nodist
- MAC/Linux: NVM or N
NVM generally does not support Windows systems, but may support WLS (Linux subsystem under Windows)
6.3.2 About Global Node/NPM
-
n
:Since NPM is installed in /usr/local/lib/node_modules, the global node/ NPM directory is actually shared when using n to switch between different node versions. Therefore, the need to use different global Node modules for different Node versions is not well met.
-
nvm/nvm-windows
:Do not share global node/ NPM between different versions. “Use different global Node modules according to different Node versions”
6.3.3 About Node Dependencies
-
n
:N depends on node. You must install node before installing n
-
NVM/NVM – Windows:
The installation of Node depends on NVM/NVM-Windows, that is, the computer does not need to have a Node environment before installing NVM or NVM-Windows.
6.3.4 Attributes about itself
-
n
:N Exists and is developed based on node modules
-
NVM/NVM – Windows:
NVM/NVM-Windows is a separate package, and NVM-Windows was developed with GO
6.3.5 Operations Before Installation
-
n
:N You do not need to uninstall an installed node
-
NVM/NVM – Windows:
Before installing NVM/NVM-Windows, you need to uninstall all existing Node versions, remove any existing NodeJS installation directories that may remain, and remove existing NPM installation locations
6.3.6 Operations After the Installation
-
n
:After installing n, installed global modules do not need to re-install global NPM applications (e.g. glup,webpack) in most cases, because N shares global Node modules
-
nvm/nvm-windows
:NVM/NVM-Windows needs to be re-installed with global NPM applications (e.g. glUP,webpack) for each Node version, since NVM/NVM-Windows does not share global Node modules
6.4 NVM/NVM-Windows and N
For NVM/NVM-Windows with n, an example:
Compare the Node version to a sibling. All installed global NPM applications (e.g. Glup, Webpack) are compared to a house already built. The switching version of the job is the equivalent of assigning someone to look after your home. Let’s say your dad and your uncle split up, you live in the same house with your siblings, and you live in separate houses with your Cousins
When you manage Node with n, the node version is you and your brother, all living in the same house; You watch the house, and your siblings watch the house, watch the house, are the same house (sharing the same node module);
When managing Node with NVM/NVM-Windows, the Node version is that you and your Cousins don’t live in the same house. Your house is your house, and your cousin’s house is your cousin’s house. When you look at the home, you must look at the home and your Cousins look at the home is not the same house (do not share the same node module), difficult to you look at your Cousins ah!! Your cousin didn’t give you millions, give me some, I will watch your house
6.5 NVM – Windows official website translation
1. First of all, translation from the official website of NVM-Windows:
— — — — — — — — — — — — — — — — — — — — — — — — translation began to — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
Node.js has several version managers. Tools like NVM and N only run on Mac OSX and Linux. Windows users left out in the cold? Not at all. Both NVMW and NOdist were designed for Windows.
First, this version of NVM (meaning NVM-Windows) does not depend on Node. It's written in Go...
The control mechanisms are also quite different. There are two general ways to support multiple Node installations with hot swap. The first is to change the system path each time you switch versions, or to bypass it by emulating the node executable using a.bat file and redirecting it accordingly. In my opinion, this was always a bit dated, and there were a few quirks due to the implementation.
The second option is to use symbolic links. This concept requires placing symbolic links in the system path and then updating their target to the node installation directory to be used. It's a straightforward approach that seems to be recommended... Until they realized how painful symlinks are on Windows. That's why it hasn't happened before.
In order to create/modify symlinks, you have to run as an administrator and you have to bypass Windows UAC(that annoying prompt). Fortunately, I’ve solved this problem in some help scripts in Node-Windows. Therefore, NVM for Windows (meaning NVM-Windows) maintains only a symbolic link that is placed in the system path only during installation. Switching to a different version of a node switches symbolic link targets. Therefore, this utility does not require you to run NVM (NVM-Windows) using X.x. Open the console window every time. When you run NVM, use x.x. The active version of the node is automatically updated in all open console Windows. It also persists between system reboots, so you only need to use NVM when you need to make changes (using the NVM command with nVM-Windows).
NVM for Windows (NVM-Windows) comes with an installer that is a byproduct of my work on the Fenix Web server.
Overall, this project (NVM-Windows) brings together some ideas, some battle-hardened parts of other modules, and support for newer versions of Node.
NVM for Windows uses the list provided by the Node project to identify the "latest" version. Version 1.1.1+ uses this list. Before this list existed, I had been collecting distributions and providing them as separate data feeds. This list was used in version 1.1.0 and earlier, but is not recommended now.
— — — — — — — — — — — — — — — — — — — — — — — end of translation — — — — — — — — — — — — — — — — — — — — — — — — — — — —
—
The concepts involved in the above translation are as follows:
- A symlink is an indirect pointer to a file
You can learn about symlink and hard linking by following the tutorial links below
- Symlink creation and reading and writing — Symlink, readLink;
- UNIX(Programming – Files and Directories):11– Symlink, ReadLink (Recommended reading)
Nvm-windows Install Multiple Versions of Node
After three days of writing, the focus finally came. First, I repeated the simple description and considerations of NVM-Windows
7.1 NVM – Windows
- Nvm-windows is a command line tool
- Nvm-windows is not a simple port of NVM, nor are they related.
- Nvm-windows is often referred to as NVM for short, but use the nVM-Windows name whenever possible
- Nvm-windows When switching node versions, NPM modules are not shared between different node versions.
- Before installing NVM-Windows:
- Uninstall any existing version of Node.js installed on your computer
- Delete any existing NodeJS installation directories that may remain (for example, “C:\Program Files\nodejs”)
- Remove the existing NPM installation location (for example. C:\Users\AppData\ NPM “), in order to correctly use the NVM installation location
- This is required after the nVM-Windows installation is complete
- Must be
each
Reinstalling global utilities such as gulp/webpack on installed versions of Node requires reinstalling all applications or command lines previously installed on node. If you only use one version of Node, you can reinstall it, but if you switch to another version of Node and want to use the application from the previous version of Node, you need to reinstall it
7.2 Procedure Before Installation
The following example, I use windows7
Assume you have installed Node before, and NPM installs modules globally, and is used for window command execution (non-project operations). (For those who have not installed Node and global modules or do not need these commands, please visit ————skip )
If the NPM global installation module is only used for window command operations and not for project operations, skip this step. The package.json file is included in the project, and you only need NPM install to install all the dependencies required by the project after installing Node. You do not need to re-install one by one, please skip ————)
In order to ensure that your global modules are available in the command window (not required by your project), it is best to take a screenshot of which NPM global modules you have installed.
Before you do this, you should understand the difference between a global and a local nodeJS installation, and how to use NPM to view globally installed and locally installed modules. Please read the following tutorial links and come back.
【原 文 】 The difference between nodeJS global installation and local installation;
NPM view modules
1.1 shortcut keys [win+R] The search window pops up, entercmd
, — — –(Next step)
1.2. Press Enter. In the CMD command window, enter ——————(Next step)
npm list -g --depth 0
Copy the code
If not added –depth 0 will show a more detailed list. We don’t need to display the details here.
1.3. Press Enter to view the installedNPM global module
], and save screenshots, or copy save (must save !!!!) — — –(Next step)
1.4, go to your project, find the [node_modules] folder (node module package), copy and save a copy ——————(Next step)
If the dependencies and devDependencies configuration in package.json are standard, you don’t need to copy node_modules. After installing Node, go to the project and use the command NPM install to download the node_modules dependencies
For more information about dependencies and devDependencies, read: Proper posture for Dependencies and devDependencies
[Step 2] uninstall any existing version of Node. js installed on the computer and delete the path
You may be wondering:
Uninstalling NPM or Node first?
npm is written in Node.js, so you need to install Node.js in order to use npm. You can install npm via the Node.js website, NPM is written in Node.js, so you need to install Node.js to use NPM. You can install NPM through the Node.js web site, or install Node version Manager or NVM.
NPM must be in Node.js!! ;
Why not uninstall node from uninstall Node.js, instead of using the computer’s own programs and functions?
- First of all, we do not know whether you use exe to install node, or MSI to install Node, so Windows according to exe or MSI to install node software process we do not know the details. Msi and EXE installation difference, please understand by yourself.
- However, the uninstallation of uninstall Node.js provided by Node may cause residues.
Why do I need to view the Node or NPM installation path on CMD?
- In order to remove Node.js completely, we need to delete the previous installation path completely. Uninstalling the installation path does not completely remove the entire folder.
.
2.1. Enter the following command under CMD and press EnterView and save the node.js installation path
— — –(Next step)
where node
Copy the code
or
where npm
Copy the code
2.2. Enter [Control Panel], select [All Control Panels], select [Programs and Functions], and find the installed programsNode.js
, right-click the mouse and uninstall ——————(Next step)
2.3. Verify that Node has been uninstallednode -v
The following information is displayed: ——————(Next step)
(Forgive me for changing a computer to operate the demo screenshots, because the network is really bad, refresh a page can not brush out, stop nagging, continue to write)
“Node” is not recognized as an internal or external command, operable program, or batch file.
There is no need to check whether NPM is uninstalled, because NPM is written to node.js. Uninstalling Node means that NPM is also uninstalled.Copy the code
[‘node’ is not an internal or external command, nor is it a runnable program or batch file]
【’node’ is not recognized as an internal or external command,operable program or batch file.】
2.4, restart the computer (let the computer software registry refresh, la la la ~, delete library run) ——————(Next step)
2.5, after the restart (boot touch fish mixed basic salary) ——————(Next step)
2.6. Delete the node installation path and the global module installation path ——————(Next step)
If you uninstall node.js using uninstall node.js, you need to find the Node installation directory where the previous record was saved, go to that directory, and then delete the folder. For example, in this case, I deleted: C:\Program Files\nodejs, if you uninstall node.js according to [2.2 steps], you do not need to delete the node installation directory, go to —————— (next step).
2.7. Delete machine-environment variables (and user variables) and references associated with Node
Click computer -> System Properties -> Advanced System Settings -> Environment Variables
-
Delete the path of the user variable and the path of the system variable respectively
- If your node path is added by reference, remove both the node reference and the node reference from the path variable. Here, since I only added the Node path to the system variable, I removed the node path from the system variable, which is highlighted in red
How do I know which environment variables and files need to be deleted? Locate the following paths and delete the folders and environment variables (user and system variables) corresponding to these paths, if any.
C:\Program Files (x86)\Nodejs
Copy the code
C:\Program Files\Nodejs
Copy the code
C:\Users\`{User}`\AppData\ Folder \ NPM (or % AppData %\ NPM)Copy the code
C:\Users\`{User}`\ AppData \ Roaming \ NPM - cache (or % AppData % \ NPM - cache)Copy the code
C:\Users\`{User}`\.npmrc (no ". Prefixes may also need to be checked.Copy the code
C:\Users\`{User}`\AppData\Local\Temp\ NPM -* (Folder beginning with NPM -)Copy the code
If your computer’s drive C does not show hidden files with a ‘. ‘prefix, please show the hidden files, remember to delete the relevant path, set the default value!!
Win7 the following operation:
Win8 need in the upper right of the window first put [hidden items] to √, then click on the right side of the [options]…
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Here, I delete
C:\Users\HDMI\AppData\Roaming
NPM and nPm-cacheC:\Users\HDMI\AppData\Local\Temp
Npm-3328-b046e407, nPM-7492-60989C8F, nPM-8352-F82062A1
— — — — — — — — — — — — — — — — — — — — summary in a word, and the node to delete/NPM all * * * — — — — — — — — — — — — — — — — — — — — — — — — — — — — remember after remove the related path, to show hidden files set back to default value!!
2.8 congratulations, you successfully uninstalled Node.js/NPM completely and deleted the related path
— — — — — — — — — — — — — — — — — — — — — — — — — — — — good for almost a week, finally liberation — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — –
7.3 Procedure for installing NVM-Windows
Go to GitHub of NVM-Windows,Download the latest version of NVM-Windows
As you can see, there are two ways:
nvm-noinstall.zip
: Green version, need to configure (novice or through the green version)nvm-setup.zip
: Installation package. No configuration is required.
— — — — — — — — — — — — — — — — — — — — — — — — here we choose NVM – setup. Zip installation — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — –
When unzipped, it’s an exe,
Double-click to enter the installation
Before installation, you are advised to close the antivirus software and exit
1. Agree to the agreement, next
2. Configure the INSTALLATION location of the NVM (do not include the Chinese path or space). After you select the path, it adds the \ NVM suffix to you by default (easy to identify).
3. Set the location of the Symlink folder. (Do not have Chinese path or space). This is the directory where NVM use will store your nodejs program. After installation, this directory will be deleted automatically
4. If you have Node installed on your computer before installing NVM, you will be asked if you want to use NVM to manage existing Versions of Node. Make sure you say yes, because it’s gonna pop up a couple of times, all of them. (If you have followed 7.2 Steps before Installation above, this message will not appear. It is also recommended that you follow 7.2 Steps before Installation above, otherwise you will have problems using Node later.)
5. Check the path you follow. If you want to view or change any Settings, click Back
6. If the following security prompt appears, please close and exit the antivirus software, or choose to allow all operations of the program (it is recommended to close and exit the antivirus software)
7. The installation is complete
8. Check whether nVM-Windows is successfully installed: Key [win+R], enter CMD, and press Enter to open the CMD command window
nvm -v
Copy the code
If the version number is displayed, it is successful, as follows: Open a command line with administrator rights. Enter NVM v. The NVM version is displayed. If yes, the installation is successful.
9. Configure a mirror ———— Skip
Let’s get started:
After that, in your NVM-Windows installation directory,
(1) Check setting.txt, you will find that there are only [root] and [path] in it.
(2) Double-click to run install. CMD, and it will ask you to type “zip file decompress or copy to an absolute path”
Open and edit the [node_mirror] and [npm_mirror] as the mirror you want, leave everything else untouched. At this point, I enter the path to install NVM-Windows
I configured taobao mirror as follows:
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
Copy the code
The setting. TXT is as follows:
Note: do not change the original parameters, just add the mirror
(4) If your NVM-Windows installation path does not have setting.txt. Please follow the above steps first, or one of them:
root
:Nvm-windows installation path
Root: C:\dev\ NVM, root: must be followed by a spacepath
:The directory where the Node shortcut resides
Path: C:\dev\nodejs, path: must be followed by a spacearch
:The bits of the operating system
— Bits configured for the current operating system (32/64)proxy
: proxy. No configuration is required
10. Configure environment variables
Nvm-windows, installed with the nVM-setup. zip installation package, will default to adding environment variables like the following:
[System variables]
[User variable]
Although the user variable is missing NVM_SYMLINK, the system automatically looks for the system variable and also finds NVM_SYMLINKCopy the code
Note: Root: and path: must be followed by a space otherwise they will not be installed in the NVM folder during node installation
If no, you need to configure it manually
Precautions for manual configuration:
- The order of NVM_HOME and NVM_SYMLINK environment variables must not be changed. Create NVM_HOME first and then NVM_SYMLINK
How do I check that the environment Settings are correct?
Open CMD and run the set NVM_HOME and set NVM_SYMLINK commands to check whether environment variables are successfully configured
7.4 Installing Node using NVM-Windows
Command to install node
NVM install
[arch]
This can be the Node.js version or the “latest” version of the latest stable version. Optionally specify whether to install the 32-bit or 64-bit version (the default is System Arch). Set [ARCH] to “all” to install the 32-bit and 64-bit versions. Wherein [arch] is the arch downloaded from setting. TXT file in the nVM-Windows installation directory
Nvm-windows install Node.js options include:
- NVM install [version number] Installs a fixed version of Node
- Such as:
NVM install 6.10.2
Install Node.js version 6.10.2
- Such as:
Copy the code
- NVM install Latest Installs node of the latest version
- Such as:
nvm install latest
Install Node.js version 6.10.2
- Such as:
nvm install latest
Copy the code
Nvm-windows using Node.js options are:
- NVM use [version number] The current node version is used
- Such as:
NVM use 6.10.2
Use version 6.10.2 of Node.js
- Such as:
nvm use 6.102.
Copy the code
Nvm-windows installs node.js/ NPM instances
(1) Open CMD and run NVM install latest to install the latest 12.5.0
nvm install latest
Copy the code
Meanwhile, it will automatically install NPM for us
(2) Run NVM use 12.5.0 and press Enter to use Node.js 12.5.0
nvm use 12.5. 0
Copy the code
(3) Test whether the Node is successfully installed. Enter node -v and press Enter to view the node version number
node -v
Copy the code
And you’ll notice that in our path corresponding to setting. TXT we can see that there is a shortcut for Node
Note: If you are testing for a successful installation of Node, make sure you have entered the node command NVM use 12.5.0 and press Enter.
“Node” is not identified as an internal or external command, actionable program, or batch file.
X. Reference links:
-
The relationship between JavaScript, Node.js and V8
-
What is the node. Js
-
Three main features of Node.js
-
NodeJS features and application scenarios
-
Node.js features and application scenarios
-
What is NodeJS? Why learn? What are the advantages and disadvantages?
-
How to select the difference between LTS and Current in Node.js?
-
Understand node.js releases
-
Introduction and use of NVM
-
To manage node versions, choose NVM or N?
-
Using NVM to manage different versions of Node and NPM
-
A brief introduction and installation of WSL(Linux subsystem on Windows)
-
WSL (Linux Subsystem under Windows)
-
Symlink creation and reading and writing — Symlink, readLink;
-
UNIX(Programming – Files and Directories):11– Symlink, ReadLink
-
What is high concurrency, explain in detail
-
Do you know what high concurrency is? The idiom is guaranteed to be understood
-
Introduction and use of NVM
-
The difference between nodeJS global installation and local installation
-
NPM view modules
-
The correct posture for dependencies and devDependencies
-
Bring up the hidden files
-
NVM installation and precautions
-
Install and use NVM in Windows
-
NVM is installed and used in Windows