Home > Web Front-end > JS Tutorial > A brief discussion on how to install global node modules offline

A brief discussion on how to install global node modules offline

青灯夜游
Release: 2021-09-27 10:53:59
forward
2931 people have browsed it

How to install the global node module offline? The following article will introduce to you how to install the global node module offline. I hope it will be helpful to you!

A brief discussion on how to install global node modules offline

How do you usually install node modules offline? [Recommended learning: "nodejs Tutorial"]

Preface

In daily development, we usually install it online. It is possible to install the node module, but it is not guaranteed that there will be a need for offline installation. For example, if the company's intranet is not connected to the Internet, what should I do if I need to install a module?

Today, I will summarize a method of offline installation of the node module by installing the global asar module offline.

Preparation

Installation environment: MacOS

Since it is an offline installation, you first need to download the corresponding module through the network. In this article, npm install -D asar is used to download the asar module and its dependencies. The file structure is as follows:

A brief discussion on how to install global node modules offline

Offline installation of global asar

The principle of method one is the same as when we install the node module online, install it directly through npm intall -g XXX.

First, we create a new node_modules folder under the asar folder, and move all the folders under test/node_modules except .bin and asar to test/ Under the node_modules/asar/node_modules folder, the structure is as follows:

A brief discussion on how to install global node modules offline

Execute the following command in the terminal (the path is test/node_modules/asar Absolute path):

 npm install -g /Users/code/test/node_modules/asar复制代码
Copy after login

Then execute asar -V in the terminal at any location to verify whether the installation is successful. The results are as follows:

A brief discussion on how to install global node modules offline

means that the asar module has been successfully installed and you're done!

Notes

On MacOS, the global module installed through this method only generates a soft link to the global command. Verify as follows:

Execute where asar and get the result:

A brief discussion on how to install global node modules offline

Then go to the path /usr/local/bin/asar to find asar and check Its attributes:

A brief discussion on how to install global node modules offline

So, never delete or rename the test/node_modules/asar/ file path, otherwise the global asar will fail!

Under windows, after using this method, the entire asar folder is completely copied to AppData/Roaming/npm/node_modules. Deleting the original asar folder does not affect the use.

Summary

The above is a simple method to install the global node module offline. I hope it will be helpful to everyone!

Of course, there is more than one way to install node modules offline. How do you usually install node modules offline? Welcome to discuss and exchange in the comment area!

~This article is over, thank you for reading!

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of A brief discussion on how to install global node modules offline. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template