Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

How do you install the Node module offline?

preface

In normal development, we usually install Node modules through online installation, but there may be a need for offline installation. For example, the Intranet of the company is not connected to the Internet, so what if you need to install modules?

Today, I’ll summarize how to install a Node module offline by installing the global ASAR module offline.

The preparatory work

Installation environment: MacOS

Since it is offline installation, it is necessary to download the corresponding module through the network first. In this article, NPM install -d asar is used to download the ASAR module and its dependencies. The file structure is as follows:

Install the global ASAR offline

The principle of method 1 is the same as we install the Node module online, directly through NPM intall -g XXX to install.

First, we’ll create a new node_modules folder under the ASar folder, And move the test/node_modules folders except.bin and asar to the test/node_modules/asar/node_modules folder. The structure is shown as follows:

Run the following command on the terminal (the absolute path is test/node_modules/asar) :

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

Then run asAR -v on any terminal to verify whether the installation is successful. The result is as follows:

Indicates that the ASAR module has been successfully installed, and you are done!

Matters needing attention

On MacOS, the global module installed this way just generates a soft link of the global instruction, verified as follows:

Execute where asar and get the result:

Then go to /usr/local/bin/asar to find asar and check its properties:

Do not delete or rename the test/node_modules/asar/ file path, otherwise the global ASAR will fail!

On Windows, the asAR folder is copied to the AppData/Roaming/ NPM /node_modules folder after this folder is used. Deleting the original ASAR folder does not affect the usage.

conclusion

This is a simple way to install the global Node module offline. I hope you can help!

Of course, there is more than one way to install a Node module offline. How do you install a Node module offline? Welcome to discuss in the comments section!

~

Thanks for reading!

~

Learn interesting knowledge, meet interesting friends, shape interesting soul!

Hello everyone, I am the author of “programming Samadhi”, I am king Yi, my public account is “programming Samadhi”, welcome to pay attention, I hope you can give me more advice!

You come, with expectations, I have ink to welcome! You return, no matter gain or loss, only to yu Yun give each other!

Knowledge and skills should be paid equal attention to, internal force and external power should be repaired simultaneously, theory and practice should grasp both hands, both hands should be hard!