Do you know how to install the global node module offline?

Time:2021-12-9

Do you know how to install the global node module offline?

How do you usually install the node module offline?

preface

In normal development, we usually install the node module through online installation, but it is also incomplete, and there will be the need for offline installation. For example, the company’s intranet is not networked, so what if you need to install modules?

Today, I will summarize the method of installing the node module offline 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 paper, throughnpm install -D asarTo download the ASAR module and its dependencies. The file structure is as follows:

Do you know how to install the global node module offline?

Offline installation of global ASAR

The principle of method 1 is the same as that of installing node module onlinenpm intall -g XXXTo install.

First, we create a new node under ASAR folder_ Modules folder, andtest/node_modulesMove all folders except. Bin and ASAR totest/node_modules/asar/node_modulesUnder the folder, the structure is as follows:

Do you know how to install the global node module offline?

Execute the following command at the terminal (path:test/node_modules/asarAbsolute path to:

 npm install -g /Users/code/test/node_modules/asar

It is then executed in a terminal at any positionasar -V, verify whether the installation is successful, and the results are as follows:

Do you know how to install the global node module offline?

It means that ASAR module has been successfully installed. It’s done!

matters needing attention

On MacOS, the global module installed through this method only generates a soft connection of global instructions. The verification is as follows:

implementwhere asar, the results are as follows:

Do you know how to install the global node module offline?

Then go to the path/usr/local/bin/asarFind ASAR and view its properties:

Do you know how to install the global node module offline?

So, never delete or renametest/node_modules/asar/File path, otherwise global ASAR will become invalid!

Under windows, after using this method, the entire ASAR folder is completely copied toAppData/Roaming/npm/node_modulesUnder, deleting the original ASAR folder does not affect the use.

summary

The above is a simple way to install the global node module offline. I hope it can be helpful to you!

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

~

~End of this article, thank you for reading!

~

Learn interesting knowledge, make interesting friends and shape interesting souls!

Hello, I’mProgramming samadhiAuthor ofRecluse KingMy official account is “Programming samadhi“Welcome to pay attention. I hope you can give me more advice!

You come, with expectations, I have ink to greet you! You return, no matter gain or loss, only with the rhyme!

Pay equal attention to knowledge and skills, cultivate both internal and external skills, grasp both theory and practice, and be hard on both hands!