Nodejs / npm: how to reinstall / recompile copied application packages

Setup:

  • On a VM with an Internet connection, where npm install will be executed to install all the application dependencies. The result will be a folder with the application and its dependencies in node_modules .

  • Between the application modules there is fi: mongoose , which during installation uses node-gyp to compile its own BSON extension.

  • The application folder is copied to another virtual machine without an Internet connection and is fully functional, but the compiled extensions do not work, but its .js backups.

Question:

How to reinstall / recompile / restore all application modules on a new virtual machine without an Internet connection?

+5
source share
1 answer

This is exactly what the npm rebuild command does. Just run npm rebuild inside your application directory after copying it to a new virtual machine and any binary add-ons will be recompiled according to the current processor architecture and version of node. If the initial npm install before the copy was fully successful, npm rebuild on the second virtual machine does not need to load anything. Just make sure that the second virtual machine has a reasonably close version of node and the corresponding compilers, libraries, etc. (Build-essential and python on debian, for example).

+11
source

Source: https://habr.com/ru/post/1208183/


All Articles