Master NVM, NRM and NPM: powerful tools for Node.js development

introduction:

In the field of Node.js development, version management and package management are indispensable. This article will introduce three important tools: NVM, NRM and NPM, and how they can help developers better manage the Node.js environment and dependency packages.

Background introduction:

When it comes to Node.js, NVM (Node Version Manager) and NRM (Npm Registry Manager), these are very important tools and concepts in Node.js development. Here is a brief introduction to them:

Node.js:

Node.js is a JavaScript runtime environment based on the Chrome V8 engine for building server-side and web applications. It allows you to write high-performance applications on the server side using the JavaScript language instead of just executing JavaScript in the browser. Node.js has non-blocking, event-driven features and is suitable for building high-throughput real-time applications such as web servers, API servers, chat applications, etc. Node.js also has a powerful package manager, NPM, for managing dependencies and modules.

NVM(Node Version Manager):

NVM is a tool for managing Node.js versions. It allows you to install multiple Node.js versions simultaneously on the same computer and easily switch between them to suit different project needs. NVM is especially useful in development, as different projects may require different versions of Node.js to run. NVM allows you to freely switch Node.js versions between projects without reinstalling or uninstalling.

NRM(Npm Registry Manager):

NRM is a tool for managing Npm mirror sources. Npm is a package manager for Node.js, used to install, publish and manage JavaScript packages. Npm's default mirror source may be slower to access in some regions or network environments. NRM allows you to easily switch Npm mirror sources to speed up package downloads and installations. This is important for speeding up the development of Node.js projects, especially when you rely on a large number of third-party packages.

Summarize:

  • Node.js is a powerful JavaScript runtime environment for building server-side and web applications.
  • NVM is a tool for managing Node.js versions, allowing developers to easily switch between different versions of Node.js.
  • NRM is a tool used to manage Npm image sources and is used to speed up the download and installation of packages.

These tools play a key role in Node.js development, allowing developers to manage dependencies and versions more effectively and improve development efficiency.

How to use NVM:

Install NVM:
Installing NVM (Node Version Manager) on Windows and macOS, configuring NVM, and understanding common NVM commands are important steps for managing Node.js versions. Here are detailed instructions:

Install NVM on Windows:

  1. First, make sure your Windows operating system has Node.js installed. If not, please download and install Node.js from the Node.js official website.

  2. Open a browser and visit the NVM-Windows GitHub repository .

  3. From the GitHub page, download the latest version of the NVM-Windows installer (nvm-setup.zip). Choose the appropriate version based on your system architecture (32-bit or 64-bit).

  4. Unzip the downloaded ZIP file and run it nvm-setup.exe.

  5. During the installation process, please follow the installation wizard's prompts to complete the installation.

  6. After the installation is complete, open a command prompt or PowerShell and execute the following command to verify that the NVM installation was successful:

    nvm version
    

Install NVM on macOS:

  1. Open Terminal.

  2. Use curl to download the NVM installation script. Enter the following command:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
    

    Please note that the version numbers in the above link may change. You can find the latest version number on the official GitHub repository .

  3. The installation script downloads and installs NVM. Once completed, close and reopen the terminal, or enter the following command to enable NVM immediately:

    source ~/.bashrc
    

Configure NVM:

Whether you installed NVM on Windows or macOS, the configuration process is basically the same.

  1. Check whether NVM was successfully installed and what Node.js versions are available:

    nvm --version
    nvm ls-remote
    
  2. Choose a Node.js version to install, for example:

    nvm install 14.17.6
    
  3. Set the default Node.js version:

    nvm alias default 14.17.6
    

Commonly used NVM commands:

Here are some commonly used NVM commands that are universal whether you are using Windows or macOS:

  • Install a specific version of Node.js:

    nvm install <version>
    
  • Switch to a different Node.js version you have installed:

    nvm use <version>
    
  • View a list of installed Node.js versions:

    nvm ls
    
  • View all available Node.js versions:

    nvm ls-remote
    
  • Set the default Node.js version:

    nvm alias default <version>
    

These commands can help you manage Node.js versions and easily switch between different versions of Node.js according to project needs. Please use NVM according to your operating system and needs. If you need more help or have any questions, please feel free to ask.

How to use NRM:

Installing NRM (Npm Registry Manager) on Windows and macOS, configuring global NRM, and understanding common NRM commands are important steps for managing Npm mirror sources. Here are detailed instructions:

Install NRM:

  1. Open Terminal or Command Prompt.

  2. Install NRM globally using npm. Enter the following command in the terminal:

    npm install -g nrm
    

    This will install NRM globally via npm.

Configure global NRM:

  1. After the installation is complete, run the following command in the terminal to list the different image sources supported by NRM and the currently used image source:

    nrm ls
    
  2. Choose an Npm mirror source, such as the official source (npm), and set it as the default mirror source. Run the following command:

    nrm use npm
    

    This will set Npm's default mirror source to the official source.

Commonly used NRM commands:

Here are some common NRM commands that are universal whether you are using Windows or macOS:

  • List all available Npm mirror sources:

    nrm ls
    
  • Switch to a different Npm mirror source:

    nrm use <registry-name>
    

    For example, to switch to Taobao Npm mirror source, you can run:

    nrm use taobao
    
  • Add a custom Npm mirror source:

    nrm add <registry-name> <registry-url>
    
  • Delete the existing Npm mirror source:

    nrm del <registry-name>
    
  • Test the response time of each mirror source:

    nrm test
    

These NRM commands help you easily switch between different Npm mirror sources to meet project needs or increase package download speed.

Whether you are using Windows or macOS, NRM is a useful tool to help you manage Npm mirror sources more efficiently. If you need more help or have any questions, please feel free to ask.

Summarize:

In Node.js development, NVM, NRM, and NPM are indispensable tools that can help you manage versions and dependencies more easily. By mastering these tools, you will be able to develop Node.js applications more efficiently and ensure that they are always up to date and stable.

I hope this blog was helpful, if you need more detailed information or have any questions, please feel free to ask.

Guess you like

Origin blog.csdn.net/Mrxiao_bo/article/details/132948453